Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get the best score of players?

Asked by
ksony 54
5 years ago

My players have a leaderstats with score, how to get the best score and put the name of the player with best score in a var?

I tried with getplayers () but it did not work

0
Your question suffers from the xy problem http://xyproblem.info User#24403 69 — 5y
0
I'd like more background and context than this. GopnikChan 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Here's a way to do this. This assumes you have standard leaderstats with Kills:

local Highscore = 0

for _,v in pairs(game:GetService("Players"):GetPlayers()) do
  if v:FindFirstChild("leaderstats") and v.leaderstats:FindFirstChild("Kills") then
    if v.leaderstats.Kills.Value > Highscore then
      Highscore = v.leaderstats.Kills.Value
    end
  end
end
Ad

Answer this question