Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Tons of datastore throttling errors?

Asked by
trecept 367 Moderation Voter
5 years ago
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

0
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. SCP774 191 — 5y

1 answer

Log in to vote
2
Answered by
doomiiii 112
5 years ago
Edited 5 years ago

You are probably calling this function way too often, and every time you call it (no matter how often or at what frequency), it will definitely try to save once, and if it fails the first time, it will try to save twice.

That is why you might want to add the code that calls the SaveData function, and then also add everything related to that caller code, e.g.:

  1. Is the caller code in a single script?
  2. Could it be that SaveData is called by code that is not properly debounced, e.g. from a Touched event handler?
  3. Could it be that the caller script gets copied, thereby increasing the chance of the script being called multiple times?

And so on...

The key: Make sure, you don't try to call any code that loads or saves data too many times.

Ad

Answer this question