Does anyone know why this might fail? There is nothing in output at all.
The game.ReplicatedStorage.Events.Functions.GetSave:Invoke(plr) returns a table similar to {0,0,{1}}.
The reason I am using a different datastore for the Cash is so that I can do a worldwide cash leaderboard.
I know that this function is not working properly because whenever I use my load function…
Load function
local function load(plr)
local r
if datastore:GetAsync("User=" .. plr.UserId) then r = datastore:GetAsync("User=" .. plr.UserId) else r= {0, 0, {1}}end
local t = { r , (cashDs:GetAsync("User=" .. plr.UserId) or 100)}
return t
end
… and I print print(data[1][3][1]) (which should print “1”) gives the error attempt to index nil with number; which makes me wonder if the table is saving properly.
Save function:
local function save(plr)
local function s()
datastore:SetAsync("User=" .. plr.UserId, game.ReplicatedStorage.Events.Functions.GetSave:Invoke(plr))
cashDs:SetAsync("User=" .. plr.UserId, plr.leaderstats.Cash.Value)
end
local success, msg = pcall(function()
s()
end)
if not success then
local count = 0
warn("Hit an error saving " .. plr.Name .. "'s data. Message: " .. msg .. ", attempt " .. count .. ".")
repeat
local success, msg = pcall(function()
s()
end)
count = count + 1
wait(5)
until success or count == 5
if count == 5 then warn("Save failed completely for " .. plr.Name .. ".") end
end
end
Thanks, Winky.