If every player has some value how do i make the top 3 people with the most value show up on #1, #2 and #3 text labels on one server after the game is over
I would first all of the players in the game with their value. U can do that with a for loop to get all players. After that u could set a max number value and have the closest people to that value be set up on the top 3.
Create a table with three 0 int elements.
Iterate over the players, check the values and compare against your table, save if higher and rearrange the top three as you iterate over the players.
To finish, access or create the text labels, and then set the relevant properties for whatever you need.
1. Iterate through the players in the game
2. Insert their stat and playerObject as a dictionary into a table
ex. table.insert(x, {player = player, value = yourStat
.Value})
3. Sort your table from high to low with your arguments being value index example:
table.sort(x, function(l, r) return l.value < r.value end)
Now your table is sorted and index 1 to 3 is your top 3
5. To get your top 3 you can now use local top1, top2 , top3 = x[1].player, x[2].player, x[3].player
6. Depending on how your code will be/is set up you can use a BindableEvent and optionally fire the playerName and stat and with that create your TextLabels
I hope this helped
You can use game.Players:GetPlayers() as your sorting table
I’m assuming there is a folder named ‘leaderstat’ parented to every table
local t = game.Players:GetPlayers()
table.sort(t, function(a, b)
a.leaderstat.Points.Value > b.leaderstat.Points.Value
end)
for i = 1, 3 do
--Create text labels for t[i] player objects
end