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

My Global Leaderboard only displays one player, what adjustments I can make?

Asked by 2 years ago

This only displays one player's data

local DataStoreService = game:GetService("DataStoreService")
local KillDataStore = DataStoreService:GetOrderedDataStore("KillLeaderboard")

local LeaderboardPart = script.Parent.Parent.Parent
local RefreshRate = 100

local function RefreshLeaderboard()
    for i, Player in pairs(game.Players:GetPlayers())  do

        KillDataStore:SetAsync(Player.UserId, Player.leaderstats.Kills.Value)
    end

    local Success, Error = pcall(function()
        local Data = KillDataStore:GetSortedAsync(false,10)
        local KillPage = Data:GetCurrentPage()
        for Rank, SavedData in ipairs(KillPage) do
            local Username = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key))
            local Kill = SavedData.value

            if Kill then
                local NewSample = script.Parent.Sample:Clone()
                NewSample.Visible = true
                NewSample.Parent = LeaderboardPart.SurfaceGui.PlayerHolder
                NewSample.Name = Username
                NewSample.RankLabel.Text = "#"..Rank
                NewSample.NameLabel.Text = Username
                NewSample.KillsLabel.Text = "????"..Kill
            end
        end
    end)
end

while   true do
    for i, Frame in pairs(LeaderboardPart.SurfaceGui.PlayerHolder:GetChildren()) do
        if Frame.Name ~= "Sample" and Frame:IsA("Frame") then
            Frame:Destroy()
        end
    end

    RefreshLeaderboard()
    wait(RefreshRate)
end


Answer this question