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

(SOLVED)table.sort keeps giving me an output of nil, Why?

i'm trying to use table.sort() but it's not seeming to work out for me.

Any idea what i'm doing wrong?

local list = {1,66,45,76542,3,7,324,56,8,98,46,73757,34,12,5,1,2,3,4,6,7,9,33,55,67,14}

local sorted = table.sort(list)

print(sorted)

Output:

nil

2 comments

0

you cant print a table like that you will have to loop through the table using a for loop.

0

not true, if you print a table like that it'll print the table. https://gyazo.com/8211dc3acdb32cf1df6a4c63d24b4ec5. In the gyazo I pint(list) in the provided code above.

1 answer

I would just delete the entire question because I figured it out and it was super simple... and I figure if I had this problem maybe someone else will or has as well.. So Here is the solution

table.sort() NEVER RETURNS ANYTHING so....

local list = {1,64,3,6,865,80,6,245,8,3456,997,97,0,75,3}
local a = table.sort(list)
print(a)

Output:

nil

a will ALWAYS = nil a will NEVER not = nil

Therefore... SOLUTION

local list = {1,64,3,6,865,80,6,245,8,3456,997,97,0,75,3}

table.sort(list)

print(table.concat(list, "|"))

Output:

0|1|3|3|6|6|8|64|75|80|97|245|865|997|3456

Conclusion: table.sort() sorts that list given. It does NOT create a new 'sorted' list.

I'm aware I should have known this. But I overlooked things. Hope my issue helps someone lol

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