Datastore 2 Kills Leaderboard Bug

  1. What do you want to achieve?

A simple leaderboard that displays players names, kills, and ranks. Top kills = Top Rank, etc.

  1. What is the issue?
    board problem
    The board seems to only display One Name and One Rank, if a player were to kill another person it would just overlap the Name in Rank #1.

  2. What solutions have you tried so far?
    I’ve tried looking into Datastore Editor, and have tried simply just fixing the index of the code. Little confused why this is happening.
    Also checked out this information

This is the script that displays templates onto leaderboard (it is a serverscript and it is inside the datastore2 handler) >

local function updateLeaderboard(dataStore, parent)
    
    for i,v in pairs(parent:GetChildren()) do
        if v:IsA("Frame") then v:Destroy() end
    end
    
    local success, errorMessage = pcall(function()
        local sortedData = dataStore:GetSortedAsync(false,10)
        local page = sortedData:GetCurrentPage()
        
        for rank, data in ipairs(page) do
            
            local playerName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
            local value = data.value
            
            local isOnLeaderboard = false
            
            for i,v in pairs(parent:GetChildren()) do
                if v:IsA("Frame") and v.PlayerName.Text == playerName then
                    isOnLeaderboard = true
                    break
                end
            end
            
            if value and isOnLeaderboard == false then
                local GLTemplate = game.ReplicatedStorage.ASSETS.GLTemplate:Clone()
                GLTemplate.Rank.Text = "#"..rank
                GLTemplate.Kills.Text = value
                GLTemplate.PlrName.Text = playerName
                GLTemplate.Parent = parent
            end
            
        end
        
    end)
    
    if not success then
        print(errorMessage)
    end
    
end

spawn(function()
    while wait(30) do
        
        for i,player in pairs(game.Players:GetPlayers()) do
            local killsStore = Datastore2("Kills",player)
            killsStore:Save()
            
            game:GetService("DataStoreService"):GetOrderedDataStore("Kills"):SetAsync(player.UserId, player.Kills.Value)
        end
        
        updateLeaderboard(game:GetService("DataStoreService"):GetOrderedDataStore("Kills"), workspace.KillsBoard.GlobalLB.GlobalLBGui.List)
    end
end)

Have you added a list constraint into the UI?

1 Like

image