Table.sort not working, returning nil values

Hello, I ran into a little problem when trying to sort my array table using the table.sort function however it doesn’t seem to be working since when I put this snippet…

local t = {9, 8, 7, 6, 5, 4} print(table.sort(t))

into the command bar nothing happens, when I declared it using a variable a nil gets printed. Is there any problem with how I’m doing it or could there be another problem that’s going on here?

I even modified it like this…

local t = {9, 8, 7, 6} print(table.sort(t, function(a, b) return a < b end))

but nothing happened.

I’m pretty sure table.sort just modifies the table passed in, it doesn’t return a new table.

The table still doesn’t get sorted.

What you posted isn’t even logical code :laughing: no wonder it won’t work. Edit: You deleted the code I was referencing. I am not talking about your OP.

As @Pokemoncraft5290 stated above, the table.sort function solely modifies the table. It does not return a new table.

Instead, you would need to try something like this:

local t = {9, 8, 7, 6}

table.sort(t, function(a, b) return a < b end)
1 Like

Yea I noticed the mistake I put in

1 Like