Hi guys. Im trying to create a position saver with datastore. This part below is how i saved the data. The second part is where it reads nil aways instead of the saved value.
Why is this happening?
-- saving:
local playerUserId = "Player_"..player.UserId
local character = sessionData[playerUserId].Char
sessionData[playerUserId].X = character.HumanoidRootPart.CFrame.Position.X
sessionData[playerUserId].Y = character.HumanoidRootPart.CFrame.Position.Y
sessionData[playerUserId].Z = character.HumanoidRootPart.CFrame.Position.Z
sessionData[playerUserId].x = character.HumanoidRootPart.CFrame.LookVector.X
sessionData[playerUserId].y = character.HumanoidRootPart.CFrame.LookVector.Y
sessionData[playerUserId].z = character.HumanoidRootPart.CFrame.LookVector.Z
print("saved X =",sessionData[playerUserId].X)
local tries = 0
local success
local errormsg
repeat
tries = tries + 1
success, errormsg = pcall(function() playerData:SetAsync(playerUserId, sessionData[playerUserId]) end)
-- reading:
local data
local sussess, errormsg = pcall(function() data = playerData:GetAsync(playerUserId) end)
if data then -- se tiver
warn("DataStore downloaded for", player)
sessionData[playerUserId] = data
print("reading X =", sessionData[playerUserId].X) -- prints nil
spawn(function() -- this part is constanty atualizing character info for when player leaves.
while saving and player.Character do
if character.Humanoid.SeatPart ~= nil then
seat = character.Humanoid.SeatPart
end
if seat then
sessionData[playerUserId].Vehicle = character.Humanoid.SeatPart.Parent.Name
else
sessionData[playerUserId].Vehicle = "None"
end
sessionData[playerUserId].Char = player.Character
print(character, "saving")
wait(2)
end
end)
Notes: I checked that "sessionData[playerUserId].Char" is saving corectly with all infos needed. Also I tried putting a generic number instead of Position.X and it keeps returning nil instead of the number, to make sure I can save Position.XYZ in datastore. The "data" variable is sussessfuly returning a table. All the data saved comes just as "nil nil nil nil".
Is it possible to be corrupt data or something like this?

3 comments
you cant save a Vector3 value in datastore =\
and moving a players head like that causes instant death
Just try it and I can try something else if it fails