PlayerPrefs Saving Player's Position Java Script

I’ve been trying to make a code where every 5 seconds my player’s position is saved. Then after turning off the game and resuming it the player will be in the last position saved. I’ve looked at different tutorials and even the responds from questions like this one. None of them have worked for me for various reasons. (Code is outdated, Not Java, etc) I’m unfamiliar with coding because I haven’t worked with Unity for some time.

So I’m asking for a Java Script code that solves this issue, or even a tutorials.

Thank you in advance. :]

On a script attached to the player, when you want to save use:

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

and when you want to restore use:

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

There are many other significantly better ways to achieve your goal.

Look for PlayerPrefsX in Google. You should come across an extended version of PlayerPrefs (created by the Unity team, I believe) that allows you to save practically all types of variables in the same way you use PlayerPrefs, including Vector3’s.

Also, parts of the above script are in C# syntax. A JS equivalent of what you wrote would be:

function Start () { 
var newPosition : Vector3 = Vector3.zero; 
newPosition.x = PlayerPrefs.GetFloat("PlayerX"); 
newPosition.y = PlayerPrefs.GetFloat("PlayerY");
newPosition.z = PlayerPrefs.GetFloat("PlayerZ"); 
transform.position = newPosition; 
} 

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

//PlayerPrefsX equivalent would be:

function Start () { 
var newPosition : Vector3 = PlayerPrefsX.GetVector3("PlayerPosition"); 
transform.position = newPosition; 
} 

function Update () { 
PlayerPrefsX.SetVector3("PlayerX", transform.position);
}