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

Is There Any Way I Can Improve This Ordered Datastore to Record People's Wins Better?

Asked by
8391ice 91
7 years ago

I want to display the players with the top 10 most wins on a board in my game, and I've learned that the best way to do so is with an ordered datastore. So I have created this script, but for some reason, the wins will sometimes lag behind. I have seen people on my game have 18 wins on the board when they actually have 20. How could I script this so that the Ordered Datastore records their wins much better?

This is my script:

local ods = game:GetService("DataStoreService"):GetOrderedDataStore("HighScore9")

function updateBoard(board, data)
    for k,v in pairs(data) do
        local pos = k
        local name = v.key
        local score = v.value
        local nametextbox = board:FindFirstChild("Name" .. pos)
        if board.Name == "Top5" then
            nametextbox.Text = " " ..pos.. ". " ..name
        else
            nametextbox.Text = " " ..(pos+5).. ". " ..name
        end
        local scoretextbox = nametextbox:FindFirstChild("Value")
        scoretextbox.Text = score
    end 
end

while true do
    local success, message = pcall(function()
        local pages = ods:GetSortedAsync(false, 5)
        local data = pages:GetCurrentPage() 
        updateBoard(game.Workspace.Leaderboards.BattleBoard.Board.SurfaceGui.List.Top5, data)
        if not pages.IsFinished then            
            pages:AdvanceToNextPageAsync()          
            data = pages:GetCurrentPage()
            updateBoard(game.Workspace.Leaderboards.BattleBoard.Board.SurfaceGui.List.Bottom5, data)
        end
    end)    
    if not success then
        print(message)
    end

    wait(60)
end
0
lower the wait amount on line 34. Be wary to not exhaust the request que on the DataStores Goulstem 8144 — 7y
0
Yeah it's all about the wait time as Goulstem said. When I did this I added a small text at the bottom with the time left til refresh. rustyhuskey 59 — 7y

Answer this question