Automatic save/load script.

I have found a verity of different scripts for saving and loading but I am trying to get it to save and load automatically, like save the game every 5 seconds and when the level starts it loads automatically. This is what I have but it’s not working…

#pragma strict
var player : Transform;
var x : float;
var y : float;
var z : float;
function Start () {
 
 if(PlayerPrefs.HasKey("x") && PlayerPrefs.HasKey("y") && PlayerPrefs.HasKey("z")) {
 
 x = PlayerPrefs.GetFloat("x");
 y = PlayerPrefs.GetFloat("y");
 z = PlayerPrefs.GetFloat("z");
 
 player.position.x = x;
 player.position.y = y;
 player.position.z = z;
 
 }
}
 
function Update () {
 
  x = player.position.x;
  PlayerPrefs.SetFloat("x", x);
 
  y = player.position.y;
  PlayerPrefs.SetFloat("y", y);
 
  z = player.position.z;
  PlayerPrefs.SetFloat("z", z);
 
}

I would go about by adding a yield WaitforSeconds(5); at the end of the update function. To save evey five seconds though you would need to create a loop like:var cups : int = 3; function Start () { if(cups == 3) }
Then execute the following code. I hope this helps.