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

Data Storing the Players Position?

Asked by 8 years ago

I've been using a work around to "You can't save Vector3's to DataStore," by saving each axis, However the results are...Not pretty.

Instead of the X, Y, and Z Coords, I get 1.2714055432228943e-023,2.9659440517425537,-1.6159910306761053e-023. Which makes sense, there are 3 of them, just...Very wrong coordinates!

When Saving

local pos = Instance.new("Vector3Value")
        pos.Value = Player.Character.Torso.Position
        local savePoint = {Player.leaderstats.Money.Value, Player.leaderstats.Allegiance.Value, 
        Player.leaderstats.Level.Value, Player.Class.Value, pos.Value.X, pos.Value.Y, pos.Value.Z}
        local saveString = Utils:JSONEncode(savePoint)
        save:SetAsync("sav_" .. Player.Name, saveString)

and then it loads it, Decodes it from JSON to table, and Moves the player based on the last 3 Values.

To be blunt, It doesn't do that...

0
Cant you just create 3 number variables for each axis and then when loading put those variables into the player's position drew1017 330 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

You could just make a datastore with the values separate, with no JSON stuff needed...

local Vector3Store = game:GetService("DataStoreService"):GetDataStore("Vector3Store") --Or whatever it is, I can't remember this late at night

Vector3Store:SetAsync("X", n)
Vector3Store:SetAsync("Y", n2)
Vector3Store:SetAsync("Z", n3)

Then, you call this entire thing up as a table, no JSON needed, and voila.

0
True point, I got this working (Somehow, I'm not quite sure of it) but I'll give you the credit as this method also worked. PuzzleMeThis 15 — 8y
Ad

Answer this question