Best way to get top player from Leaderboard?

I would like to loop through the players in my game ever couple minutes and create a statue of the leaders.

I can figure out the statue part, I just am a bit confused about how to find the leader. I have leaderboard set up fine.

Is there a simple way or will i have to do some sort of loop to do the sorting?

Thank you for reading.

Yeah use table.sort

local function sorted_by_highest()
    local player_list = Players:GetPlayers()
    table.sort(player_list, function(p1, p2)
        return p1.Points.Value > p2.Points.Value -- or whatever you want to sort
    end)
    return player_list
end

It sorts a list of players, and returns it in descending order, so the richest player is at the top

4 Likes

Thanks alot easier than i thought

Hm actually still having a little trouble.

Says" table expected got Object " in table.sort line

I changed one line in code to player_list = game:GetService(“Players”) instead of what you have there.

Edit: Nevermind needed to add :GetPlayers() on that line. Thanks you

1 Like