Hello ScriptingHelpers,
I'm making a game where every round a random player is being picked. I don't use math.random() because it has limits and downsides (it's repetitive and I couldn't make something like 2x chance gamepass). I've managed to come up with this but I can't figure out how to sort table by table's table[1]s instead of comparing the whole tables which would make an error. Basically I need to get player that has the biggest chance and the chance value itself.
chances = {}
for _, a in pairs(game.ServerStorage.Players:GetChildren())do -- I'm storing folders named as player names and I have a number value (Chance of being picked) there
table.insert(chances, {a.Chance.Value, a.Name})
end
table.sort(chances)
print(chances[#chances][1] .. " " .. chances[#chances][2])
Thank you for your time.

2 comments
Just add more of the same user in the table!
But I need them seperated