Hi everyone,
I know how I would set this out if I could set the data structure out beforehand, by doing:
local array = { foldername = {child, child}; foldername = {child, child} }
But how do I do this when I just can't foresee how many folders (or any other object for that matter) and need a variable amount of secondary arrays?
I tried this, but it errors.
local array = {} for i, v in pairs(sp:GetChildren()) do if v:IsA("Folder") then table.insert(array, v) for _, x in pairs(v:GetChildren()) do table.insert(array[i], x.Name) end end end
My output:
14:30:01.904 - Workspace.Script:5: bad argument #1 to 'insert' (table expected, got Object)
14:30:01.905 - Script 'Workspace.Script', Line 5
14:30:01.906 - Stack End
Just remember to set the key you're accessing to a table.
local array = {} for i, v in pairs(sp:GetChildren()) do if v:IsA("Folder") then array[i] = {}; -- Set it to an array so that there's actually room there for n, x in pairs(v:GetChildren()) do array[i][n] = x.Name; -- I'd advise against table.insert when alternatives exist, except for in making cleaner code. end end end