does anybody know why print(table.sort({2, 1})) returns no value? I get the same result using a local script, server script and the command bar
table.sort
doesn’t return anything, it edits the table itself.
Example:
local tableToSort = {9, 10, 6, 1}
print(tableToSort[1]) -- 9
table.sort(tableToSort)
print(tableToSort[1]) -- 1
5 Likes
ooh thank you! that makes more sense now
so it sorts tables from smallest value to greatest value?
Yes, by default. You can also pass a custom function as the second parameter to handle the sorting.
For more information, I recommend you check out:
2 Likes