I want to get every child of something, with a function, with calling the same function inside of it. But it errors saying that there's no function at all.
local GetAllChildren = function(c, t) for _,v in pairs(c:GetChildren()) do GetAllChildren(v) --The part where the function runs in itself table.insert(t, v) end end local Table = {} GetAllChildren(script.Parent, Table) print(unpack(Table))
Maybe the reason your script isn't working is because you tied a variable to a function, rather than making a standard function value. Also, you have to call the function inside itself AFTER you define the code inside the function.
Try this?
function GetAllChildren(model, tab) for i,v in pairs(model:GetChildren()) do table.insert(tab,v) if #v:GetChildren() > 0 then --prevent unnecessary recursions GetAllChildren(v) end end end local Table = {} GetAllChildren(script.Parent, Table) print(unpack(Table))
-EDIT-
Wanting to unanchor models? Use the same method as above but instead of inserting the current instance into a table, set it's anchorage to false(:
function unAchor(model) for i,v in pairs(model:GetChildren()) do -------------------------------------------------------------- --So that we don't try to unanchor non-parts if v:IsA("BasePart") then -------------------------------------------------------------- v.Anchored = false end if #v:GetChildren() > 0 then GetAllChildren(v) end end end unAnchor(script.Parent)