My code only reads nil from datastore, help?
Asked by
4 years ago Edited 4 years ago
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?
02 | local playerUserId = "Player_" ..player.UserId |
03 | local character = sessionData [ playerUserId ] .Char |
04 | sessionData [ playerUserId ] .X = character.HumanoidRootPart.CFrame.Position.X |
05 | sessionData [ playerUserId ] .Y = character.HumanoidRootPart.CFrame.Position.Y |
06 | sessionData [ playerUserId ] .Z = character.HumanoidRootPart.CFrame.Position.Z |
07 | sessionData [ playerUserId ] .x = character.HumanoidRootPart.CFrame.LookVector.X |
08 | sessionData [ playerUserId ] .y = character.HumanoidRootPart.CFrame.LookVector.Y |
09 | sessionData [ playerUserId ] .z = character.HumanoidRootPart.CFrame.LookVector.Z |
10 | print ( "saved X =" ,sessionData [ playerUserId ] .X) |
16 | success, errormsg = pcall ( function () playerData:SetAsync(playerUserId, sessionData [ playerUserId ] ) end ) |
03 | local sussess, errormsg = pcall ( function () data = playerData:GetAsync(playerUserId) end ) |
05 | warn( "DataStore downloaded for" , player) |
06 | sessionData [ playerUserId ] = data |
07 | print ( "reading X =" , sessionData [ playerUserId ] .X) |
10 | while saving and player.Character do |
11 | if character.Humanoid.SeatPart ~ = nil then |
12 | seat = character.Humanoid.SeatPart |
15 | sessionData [ playerUserId ] .Vehicle = character.Humanoid.SeatPart.Parent.Name |
17 | sessionData [ playerUserId ] .Vehicle = "None" |
19 | sessionData [ playerUserId ] .Char = player.Character |
20 | print (character, "saving" ) |
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?