Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I save the players Vector3 position to a value?

Asked by 9 years ago

I have a script that saves the X, Y and Z coordinates of players to a value in the player called X Y or Z

        player.X.Value = workspace:FindFirstChild(player.Name).Torso.Position.Vector3.x 
        player.Y.Value = workspace:FindFirstChild(player.Name).Torso.Position.Vector3.y 
        player.Z.Value = workspace:FindFirstChild(player.Name).Torso.Position.Vector3.z 

Now this doesn't work because Vector3 isn't a property of position, so how can I set the Vector3.z of the players torso to the value z?

1 answer

Log in to vote
1
Answered by 9 years ago

Just create a Vector3Value and call it something like PlayerPosition and then do the following to set the value (and make sure the player variable is the player):

player:WaitForChild("PlayerPosition").Value = player.Character:WaitForChild("Torso").Position --Waits for the Character's torso and the PlayerPosition Vector3Value in case they haven't loaded yet.

If you actually want it to save the value, so you can use it again when you join another server (let's say, for example, to respawn in the same place you left off at), use Data Stores to save each sepearate axis value from the value of PlayerPosition or use Data Persistence to save the actual PlayerPosition value object or the object's value.

However, if you want to do it the way you're doing it, just use the x, y and z properties on Position, instead of adding .Vector3 after Position, like this:

player:WaitForChild("X").Value = player.Character:WaitForChild("Torso").Position.x
player:WaitForChild("Y").Value = player.Character:WaitForChild("Torso").Position.y
player:WaitForChild("Z").Value = player.Character:WaitForChild("Torso").Position.z --WaitForChild method used on all three lines, in case any of them aren't available instantly.
0
Thank you. If I saved it to the value of Player Position, would it save as (0,0,0) for instance? and how would that be loaded back from the DataStore? Would it remain as (0,0,0)? MasterDaniel 320 — 9y
0
I just read on the Data Store wiki that you can save ROBLOX value types like Vector3, so you're going need a separate key for each axis by using player:WaitForChild("PlayerPosition").Value.x in your Data Store script when saving, with the .x at the end being your axis. Spongocardo 1991 — 9y
0
Thats my current solution. Thanks MasterDaniel 320 — 9y
Ad

Answer this question