So im trying to make a system where when a map changes, the game finds out which player has the highest of a leaderstat score. i know that math.max() will return the highest number in a set of numbers, but i would need to find out which player has that number, which again, not hard.
My problem being getting the numbers, there doesnt seem to be any easy ways to do this since math.max wont return the highest of a number if you were to do something like for _,numbers in pairs(tableHere) do print(math.max(numbers)) end
, so how should i be doing this?
You can loop over each player and compare their number to the previous highest value like so.
local function FindHighestPlayer() local Value,HighestPlayer = 0 for _,Player in pairs(game.Players:GetPlayers()) do -- loop over all players if Player.WhateverValue > Value then -- compare whatever value you want Value = Player.WhateverValue -- set HigestPlayer = Player -- set end end return HighestPlayer -- return end
If you have any questions, feel free to leave a comment.