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

Datastore throttling but not going over limit?

Asked by
trecept 367 Moderation Voter
5 years ago

I've recently advertised a game of mine and after about 4 weeks it's stopped getting players. A huge problem is when the server had 8+ players, my datastore saving system would keep throttling and loosing player data although I really don't think I was saving/loading that much. I used this load function once when a player loads into the game and I use the save function every 120 seconds and when a player leaves. I even removed the autosave at one point and I still got some errors. I unfortunately didn't look into seeing if I was actually going over the limit when the game had players but I highly doubt I was using that many requests unless over like 10 players were joining and leaving within a minute.

My code, it's a lot, does anything look weird about it? Thanks

LoadData = function(plr, Coins, Level, EXP)
    local function CheckSAVE()
        local success, msg = pcall(function()
            GetData = PlayersStats:GetAsync(plr.UserId)
        end)
        if success then
            if GetData then
                Coins.Value = GetData[1]
                Level.Value = GetData[2]
                EXP.Value = GetData[3]
            else
                Coins.Value = 0
                Level.Value = 1
                EXP.Value = 0
            end
            return true
        else
            return false
        end
    end
    local a = CheckSAVE() wait()
    if a == false then
        pcall(function()
            plr:FindFirstChild("SR").Value = false
        end)
        wait(10)
        local b = CheckSAVE() wait()
        if b == false then
            wait(1)
            warn("Error loading "..plr.UserId.." data") wait()
            plr:Kick("There was an error loading data, please rejoin or try again later!")
        elseif b == true then
            pcall(function()
                plr:FindFirstChild("SR").Value = true
            end)
        end
    end
end

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

Answer this question