Each user has a NumberValue named Votes in their Player.
I have been trying to create a script that gathers their votes and sorts them in a table. Whoever has the highest value gets eliminated.
I’m able to gather the players and theirs values into a table. I’ve sorted the values (though it’s from least to greatest), but how do I detect who has the highest value?
local EliminationTable = {}
for _, v in pairs(players:GetChildren()) do
if v.StatusFolder.inGame.Value == true then --inGame is a bool values that says whether the player is in a game or not
table.insert(EliminationTable,v.StatusFolder.Votes.Value)
end
end
table.sort(EliminationTable) -- Not sure how to make this greatest to least
print(EliminationTable[1])
local Highest = -math.huge
local PlayerToEliminate
for _, v in pairs(players:GetChildren()) do
if v.StatusFolder.inGame.Value == true then
local VoteCount = v.StatusFolder.Votes.Value
if VoteCount > Highest then --//checking if the current vote count is higher than the highest variable, if this is the first player then highest will be set to said player's vote count as any number will be lower (or technically, lower or equal to but you most likely won't ever run into a problem with this, though if you really want to be efficient:tm: you can make the highest = nil and set it to the first player's value) math.huge
Highest = VoteCount
PlayerToEliminate = v
end
end
end
print(PlayerToEliminate.Name)