Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How is table.sort used? attempt to compare two userdata values?

Asked by 7 years ago

So I am trying to get better with tables and I looked at the ROBLOX wiki and found table.sort. This is my first attempt at using table.sort and I got this error. https://gyazo.com/b76fef1653f8dfaaef630f90740570fc This is the script that I am using,

t = game.ReplicatedStorage.Stuff:GetChildren()
table.sort(t)
print(table.concat(t, ' '))

Here is what the replicatedstorage looks like, https://gyazo.com/eeedaeb30805841f6a2bd2438516466a Can anyone help with this?

1 answer

Log in to vote
0
Answered by 7 years ago

You're trying to sort objects with this - table.sort() only works with strings.

You'll have to convert it to strings, with something like the code below:

t = game.ReplicatedStorage.Stuff:GetChildren()
local newTable = {}
for i = 1, #t do
    table.insert(newTable, 1, t[i].Name)
end
table.sort(t)
print(table.concat(t, ' '))
Ad

Answer this question