Saving Location in Unity

I’m making a game in Unity, and I’m trying to use PlayerPrefs to save the player’s location. I want a script that will save the player’s position every few seconds and then when I close the game and reopen it, it will load the last place I was. Here is the code I have so far. Please help!

//saving it
var PlayerPosition = Vector3(0,0,0);
var PlayerCurrentPosition: ; //constantly changes - time function
var SavedPlayerPosition: ;

function Update ()
{
   
PlayerPrefs.SetFloat("PlayerX", transform.position.x);
PlayerPrefs.SetFloat("PlayerY", transform.position.y);
PlayerPrefs.SetFloat("PlayerZ", transform.position.z);

}

//loading it back - when to load it - on load, game start
function Update (loadPosition)
{

if () {
        
Vector3 newPosition = Vector3 ("PlayerX", "PlayerY", "PlayerZ");
newPosition.x = PlayerPrefs.GetFloat("PlayerX");
newPosition.x = PlayerPrefs.GetFloat("PlayerY");
newPosition.x = PlayerPrefs.GetFloat("PlayerZ");
transform.position = newPosition;

}

You’re saving the position correctly, there’s no problem there.

As for the second bit, well that’s not so good.

To reload the positions, all you really need to do is this:

// put it in Start, so it executes once per run:
function Start()
{
    var newXpos : float = PlayerPrefs.GetFloat("PlayerX");
    var newYpos : float = PlayerPrefs.GetFloat("PlayerY");
    var newZpos : float = PlayerPrefs.GetFloat("PlayerZ");
    transform.position = Vector3(newXpos, newYpos, newZpos);
}