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

Why is this global leaderboard returning nil for the value?

Asked by
Azuc 112
5 years ago

Everything is working fine except the datastore is returning nil for the value even though it is set as 1 in the update function.

for i = 1,11 do
    local Sam = script.Sample:Clone()
    Sam.Name = i
    Sam.Parent = script.Parent.ScrollingFrame
    Sam.UserPos.Text = "[".. tostring(i) .. "]"
    Sam.score.Text = "Nill"
    Sam.UserName.Text = ""
    Sam.LayoutOrder = i
end



function UpdateGui()
    for i,v in pairs(game.Players:GetChildren()) do
        local Data = 1
        local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("ScoreX1")
        DataStore:IncrementAsync(v.UserId,Data)
    end
    local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("ScoreX1")
    local Pages = DataStore:GetSortedAsync(false,10)
    local Data = Pages:GetCurrentPage()
    for k,v in pairs(Data) do
        if tonumber(v.key) >= 1 then
            local Frame = script.Parent.ScrollingFrame:FindFirstChild(tostring(k))
            if Frame then
                Frame.UserName.Text = game.Players:GetNameFromUserIdAsync(v.key)
                print(game.Players:GetNameFromUserIdAsync(v.key))
                print(v.Value)
                Frame.score.Text = tostring(v.Value)
            end
        end
    end
end

while true do
    UpdateGui()
    wait(2)
end
0
why do you need to do that every 2 seconds User#23365 30 — 5y
0
^ too many requests. Think more about what needs to do done and how often. User#5423 17 — 5y
0
I update my global leaderboards every two minutes. I don't recommend updating global leaderboards for less than every 20-30 seconds. User#25115 0 — 5y
View all comments (4 more)
0
Hope these links help you out! User#25115 0 — 5y
0
You're updating your values too often, update it and save it every time the Player leaves, you can simply do this with 'game.Players.PlayerRemoved:Connect(function()' then add the function(UpdateGui) inside of that function. TheOnlySmarts 233 — 5y

Answer this question