Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I put numbers in order from greatest to least?

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

1 answer

✓ Accepted answer

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.

1 comment

0

Thanks! Also, how would I get v.Name to go along with v.Value? I'm a bit inexperienced when it comes to tables.

This discussion is preserved as it was. New answers, comments, and votes are closed.