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

Ordered DataStores, What's wrong with my script?

Asked by
sgsharp 265 Moderation Voter
10 years ago

Okay, so I am making a game, and it has a GUI Ordered Leaderboard that uses ODS (Ordered DataStores). I previously had the leaderboard working on a SurfaceGui, but I wanted to turn it into a ScreenGui... So I did. And when I did, it basically stopped updating. Please tell me what I have done wrong, how I could possible fix it, and if there's a possible way to improve it.

This code is written in a regular Script...

local Data = game:GetService("DataStoreService"):GetOrderedDataStore("ScoreBoard")


game.Players.PlayerAdded:connect(function(Player)

    wait(3)

    while true do
        wait(5) 

        Data:SetAsync(Player.Name, Player.Apples.Value)

    end
end)

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.Apples:FindFirstChild("Name" .. pos)
        nametextbox.Text = name
        local scoretextbox = board.Apples:FindFirstChild("Name" .. pos).Score
        scoretextbox.Text = score
    end 
end

while true do
    local pages = Data:GetSortedAsync(false, 10)
    local data = pages:GetCurrentPage()
    updateBoard(script.Parent, data)
    if not pages.IsFinished then
        pages:AdvanceToNextPageAsync()
        data = pages:GetCurrentPage()
        updateBoard(script.Parent.Next10, data)
    end
    wait(.1)
end

Answer this question