Ad
Log in to vote
0

Why is the wins value never updating?

Asked by 13 days ago
local DataStore = game:GetService("DataStoreService")
local WinsLeaderboard = DataStore:GetOrderedDataStore("WinsLeaderboard")


local function updateLeaderboard()
    local success, errorMessage = pcall(function()
        local Data = WinsLeaderboard:GetSortedAsync(false,5)
        local WinsPage = Data:GetCurrentPage()

        for _, player in pairs(game.Players:GetPlayers()) do
            userid = player.UserId
            userID = tonumber(userid)
        end

        for Rank, data in ipairs(WinsPage) do
            local userinfo = game:GetService("UserService"):GetUserInfosByUserIdsAsync({userID})
            local username = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
            local displayname = userinfo[1].DisplayName
            local Name = username
            local Wins = data.value
            local isOnLeaderboard = false

            for i,v in pairs(game.Workspace.GlobalLeaderboard["Score Part"].SurfaceGui.Holder:GetChildren()) do
                if v.Player.Text == Name then
                    isOnLeaderboard = true
                    print("test")

                    break
                end
            end

            if Wins and isOnLeaderboard == false then
                local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
                newLbFrame.Wins.Text = Wins
                newLbFrame.Player.Text = Name
                newLbFrame.Rank.Text = "#"..Rank
                newLbFrame.PlayerDisplayName.Text = "@"..displayname
                newLbFrame.Parent = game.Workspace.GlobalLeaderboard["Score Part"].SurfaceGui.Holder

            end
        end

    end)

    if not success then
        print(errorMessage)
    end
end

while true do

    for _, player in pairs(game.Players:GetPlayers()) do
        WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Wins.Value)
    end

    for _, frame in pairs(game.Workspace.GlobalLeaderboard["Score Part"].SurfaceGui.Holder:GetChildren()) do
        frame:Destroy()
    end

    updateLeaderboard()
    print('updated leaderboard')

    wait(10)
end

Answer this question