I’m trying to use SetAsync() to save the players data to the datastore, everything works and it prints this right before saving:
But right after joining and loading using GetAsync() it prints this, notice how the ‘Instances’ table isn’t there
For those of you wanting the code:
Saving -PlotDataStore:SetAsync(player.UserId,newPlotData) (newplotdata being the table shown in the first image)
Loading - local LocalPlotData = PlotDataStore:GetAsync(player.UserId) or {} (localplotdata being the table shown in the second image without the instances array)
Let me know if you can help, Thanks! (I’m not sure any more context that I can add that would be particularly helpful, if you know something lmk!)
I think its needed to show more code cause, are u wrapping the Load and Save into a pcal?? doing retries if it fails? are u saving this when playerRemove? LocalPlotData is a variable where?
Well, all datastore queries should be in a pcall, and handle the result from the pcall to make sure data is loading and saving, would be better to paste the code to make modifications in it
This is basic example hope it helps you with handling the saving and loading data:
local DSS = game:GetService("DataStoreService")
local PlotDataStore = DSS:GetDataStore("PlotDataStore")
game.Players.PlayerAdded:Connect(function(player)
local function CheckDB(playerID)
local s, d = pcall(function()
return PlotDataStore:GetAsync(playerID)
end)
if not s then
warn("failed to check, retrying")
wait(2)
return CheckDB(playerID)
end
return s, d
end
local success, data = CheckDB(player.UserId)
if success then
warn("datastore check succesful")
if data then
warn(player, "has data, means old player")
-- TAKE THIS DATA AND SAVE IT WHEREEVER YOU WANT TO
else
warn(player, "has no data, means new player")
-- GIVE STARTING VALUES FOR THE NEW PLAYER
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local function SaveDB(playerID, Table2Save)
local s, er = pcall(function()
return PlotDataStore:SetAsync(playerID, Table2Save)
end)
if not s then
warn("failed to save, retrying")
wait(2)
return SaveDB(playerID)
end
return s, er
end
local success, err = SaveDB(player.UserId, The_Table_You_Wanna_Save)
if success then
warn("datastore saved for:", player)
end
end)
The problem is that you can only put strings and numbers in a datastore. The table you’re trying to put in is a table of instances, each of which is a table itself. The datastore can’t put those in.
You’ll have to find a way to convert the tables into strings and numbers before you save them.