How to find the player with the highest score, the second highest score, and so on? I tried this random thing, but it obviously does not work.
for _, player in pairs(game.Players:GetPlayers()) do player.PlayerGui.ScreenGui.Frame.Visible = true local first = math.max(player.leaderstats.Score.Value) local second = math.min(player.leaderstats.Score.Value) player.PlayerGui.ScreenGui.Frame.First.Text = first player.PlayerGui.ScreenGui.Frame.Second.Text = second end
Thanks!
The easiest way would be to sort the players by score using table.sort
.
function higherScoreThan(playerA, playerB) return playerA.leaderstats.Score.Value > playerB.leaderstats.Score.Value end -- get the list of all the players playing the game that have a Score local players = {} for _, player in pairs(game.Players:GetPlayers()) do if player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Score") then table.insert(players, player) end end table.sort(players, higherScoreThan) -- display the names if players[1] then FirstPlace.Text = players[1].Name if players[2] then SecondPlayer.Text = players[2].Name else SecondPlayer.Text = "only one person was playing :(" end else FirstPlace.Text = "no one was playing :(" end
Use Dummiez Leader Board Block. Here is the link; https://www.roblox.com/library/157979393/High-Score-Board
You can easily configure it to a gui.