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

What is wrong with my global leaderboard script?

Asked by 4 years ago

I'm making a global leaderboard script that displays the top 15 people with the highest win count. Here is my code so far:

for i = 1, 15 do
    local Sam = script.Sample:Clone()
    Sam.Parent = script.Parent.SurfaceGui.Frame.ScrollingFrame
    Sam.Name = i
    Sam.LayoutOrder = i
end

function UpdateGui()
    for i,v in pairs(game.Players:GetChildren()) do
        local Data = 1
        local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("TopWins")
        DataStore:SetAsync(v.UserId, Data)
    end
    local Datastore = game:GetService("DataStoreService"):GetOrderedDataStore("TopWins")
    local Pages = Datastore:GetSortedAsync(false,15)
    local Data = Pages:GetCurrentPage()
    for k,v in pairs(Data) do
        if tonumber(v.key) >= 1 then
            local Frame = script.Parent.SurfaceGui.Frame.ScrollingFrame:FindFirstChild(tostring(k))
            if Frame then
                Frame.Rank.Text = '#' .. tostring(k)
                Frame.Username.Text = game.Players:GetNameFromUserIdAsync(v.key)
                Frame.WinCount.Text = tostring(v.Value)
            end
        end
    end
end

while true do
    UpdateGui()
    wait(10)
end

For the record, I am using a separate script to keep track of every player's win count with data stores. Apparently the 'v.Value' at the bottom only returns nil. How do I fix this to return the win count from the player's data store?

Answer this question