✓ Accepted answer
table.sort(list, lessThan) sorts list in increasing order by consulting lessThan(a, b) to compute whether or not a < b.
Thus if you want to, for example, compare Vector3s by their Y-value, ascending, you could use this as your lessThan function:
function vectorYCompare(a, b)
return a.y < b.y
end
If you wanted the sort to be descending, you'd have to flip the < into a >:
function vectorYCompareDescending(a, b)
return a.y > b.y
end
If you actually had a list of Parts but you wanted to compare their locations,
function descendingParts(a, b)
return a.Position.y > b.Position.y
end
table.sort isn't stable. That means if you have "equal" elements (in this case, parts with the same Y), their order after doing the sort is undefined.
Unless you got the parts in some particular order (:GetChildren() won't give you in any particular order), this doesn't matter.
5 comments
In what way to do you want to rank them? What is your specific order?
table.sort is not reliable in that it may change equal elements' order. This will probably not be a problem for you.
I would like to rank them from Highest to Lowest . Highest being 1st Lowest being Last.
Highest as far as height or what?
EXCELLENT EXPLANATION AND ANSWER!!!