SaveData = function(plr)
local ls = plr:FindFirstChild("leaderstats")
local saveready = plr:FindFirstChild("SR")
if ls ~= nil and saveready ~= nil then
if saveready.Value == true then
local Coins = ls:FindFirstChild("Coins")
local Level = ls:FindFirstChild("Level")
local EXP = plr:FindFirstChild("EXP")
if Coins ~= nil and Level ~= nil and EXP ~= nil then
local tableofstats = {
Coins.Value,
Level.Value,
EXP.Value
}
local function AttemptSave()
local success, msg = pcall(function()
GetData = PlayersStats:GetAsync(plr.UserId)
end)
if success then
if GetData then
pcall(function()
PlayersStats:UpdateAsync(plr.UserId, function()
return tableofstats
end)
end)
else
pcall(function()
PlayersStats:SetAsync(plr.UserId, tableofstats)
end)
end
return true
else
return false
end
end
local savetest = AttemptSave()
if savetest == false then
wait(10)
local savetest2 = AttemptSave()
end
end
end
end
end
This is my datastore script, I used to have an autosave function in a while wait(120) loop (every 2 mins) and when the player leaves and I got tons of errors with datastore throttling and data loss reports which was confusing me because when I looked at the budget everything seemed ok. Now I'm only saving when the player leaves but there is still lots of datastore throttling errors and I get reports of data loss. What am I doing wrong? Thanks

1 comment
Well, you should make it auto saves every 5 mins and on player leaves, you may want to increase the delay if the player cap is high.