I am making a Highscore gui. Basically, I have a table that includes all the children of a folder named PlayerNames. All of these children are Int Values with a number as their value. How would I rank these numbers from greatest to lowest? Some of the numbers will also likely be the same.
Here is the code I started
for _,v in pairs(PlayerNames:GetChildren()) do --The numbers would be v.Value --this is where they are sorted end
Here's a solution that might work...
local values = {} -- you could probably come up with a better name for this with context for _, v in pairs(PlayerNames:GetChildren()) do table.insert(values, v.Value) end table.sort(values, function(a, b) return (a > b) end)
Essentially, what you do first is put all of the values into a table. After that, I'm using the table.sort
method to sort the table. The second parameter of table.sort
is a function that Lua uses to compute the relationship between two values.