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

[SOLVED] My datastore isn't working. Too much added to queue?

Asked by 3 years ago
Edited 3 years ago

So I have a GlobalLeaderboard script that is supposed to order the player names according to the number of wins they have.

The script below is located in ServerScriptService.

My issue is that my output says that I have too many datastore requests and if more keep coming, the older ones get deleted.

How do I efficiently stop this?

local dataStoreService = game:GetService("DataStoreService")

local players = game:GetService("Players")



local globalDataStore = dataStoreService:GetOrderedDataStore("Wins")

local board = workspace.Lobby.GlobalBoard

local template = board.SurfaceGui.LeaderBoard.Template:Clone()  

board.SurfaceGui.LeaderBoard.Template:Destroy()


local function update()

    for _,child in pairs(board.SurfaceGui.LeaderBoard:GetChildren()) do

        if child:IsA("Frame") then
            child:Destroy()
        end
    end

    local success,err = pcall(function()

    local data = globalDataStore:GetSortedAsync(false,40)

    local page = data:GetCurrentPage()


    for rank,plrData in ipairs(page) do

        local userid = plrData.key

        local wins = plrData.value

        if rank < 3 then
            local npc = workspace:FindFirstChild(rank)
                if npc then
                    npc.UserId.Value = userid
            end 
        end

        local new = template:Clone()

        new.PlrName.Text = players:GetNameFromUserIdAsync(userid)

        new.PlrAmount.Text = wins   

        new.LayoutOrder = rank

        new.Parent = board.SurfaceGui.LeaderBoard
        end
    end)
end

while true do
    update()
    wait(math.random(2,5))
    spawn(function()

        for _,plr in pairs(game.Players:GetPlayers()) do
            globalDataStore:SetAsync(plr.UserId,plr.leaderstats.Wins.Value)
            wait()
        end
    end)
end
0
There are too many spaces in your script which makes it hard to read -_- try formatting it. Coperncius 0 — 3y
0
ok sorry, will edit it right now! Lightning_Game27 232 — 3y
0
there, i made it better Lightning_Game27 232 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

This just means you are updating the datastore too frequently.

In your while true do loop you use

  wait(math.random(2,5))

But Set has a limit of 50 + (10*playerCount) per minute (https://developer.roblox.com/en-us/articles/Datastore-Errors).

You'd be best off achieving this by saving less frequently, i.e. every minute. The general advise on when to save is, when the player leaves (using Players.PlayerRemoving), when the game shutdowns (using BindToClose) and about every minute (using a loop like you have, but less frequently).

https://developer.roblox.com/en-us/api-reference/event/Players/PlayerRemoving https://developer.roblox.com/en-us/api-reference/function/DataModel/BindToClose

If you really need to update that frequently, you might be able to get away with just saving when .Changed is fired on the value.

Ad

Answer this question