#leaderboard gui player name

1 messages · Page 1 of 1 (latest)

unborn mortar
#

So i found this tutorial on the forum on how to add a player leaderboard so i tweaked it a little but then it displays the player userId instead of the player name, how do i fix this and make it display the player name?

here is the script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local plrs = game:GetService("Players")

local BestScoreStore = DataStoreService:GetOrderedDataStore("BestScoreData")

local folder = ReplicatedStorage.Leaderboard

local EntriesPerPage = 9
local refreshTime = 30

local function updateValue(rank, key, value)    
    if folder:FindFirstChild(rank) then
        local found = folder:FindFirstChild(rank)
        if found.Key.Value ~= key then
            found.Key.Value = key
            found.Value.Value = value
        end
    else
        local new = Instance.new('StringValue', folder)
        new.Name = rank

        local newKey = Instance.new('StringValue',new)
        local newValue = Instance.new('StringValue',new)

        newKey.Name = 'Key'
        newValue.Name = 'Value'

        newKey.Value = key
        newValue.Value = value
    end
end

local function Main()
    local success, pages = pcall(function()
        return BestScoreStore:GetSortedAsync(false, EntriesPerPage)
    end)

    if success then
        local entries = pages:GetCurrentPage()
        for rank, entry in ipairs(entries) do
            updateValue(rank, entry.key, entry.value)
        end
    else
        warn("Failed to get leaderboard data.")
    end
end

while true do
    Main()
    task.wait(refreshTime)
end```