I’m trying to sort my values 0 - 3 via a table so it’s easier to get a different amount of them every time. But when I try to sort them I get “nil” back? I don’t understand what’s wrong. Everything works but when I print “sortedpages” I get “nil”.
script is cut off a bit
for i,v in ipairs(pageinf:GetChildren()) do
if v:IsA("StringValue") then
table.insert(pages, v.Name)
end
end
local sortedpages = table.sort(pages, function(A, B)
return table.find(pages, A) < table.find(pages, B)
end)
print(sortedpages)
When printing the pages normally they are never sorted. I can give more info if needed.
Make sure that what you’re passing through are proper number datatypes when you’re trying to loop through your pageinf Instance
From what I see, you’re obtaining the Names & inserting that inside the table, but they aren’t converted to a number which doesn’t change anything about the table unless if you convert them to number datatypes
You have to convert the names into numbers by using the tonumber() method, then sort the table from there
for i,v in ipairs(pageinf:GetChildren()) do
if v:IsA("StringValue") then
local NumberConversion = tonumber(v.Name)
if NumberConversion ~= nil then
table.insert(pages, NumberConversion)
end
end
end
table.sort(pages, function(A, B)
return A < B
end)
print(pages)