I know that for i,v in pairs (Model:GetChildren()) will return all the children of a model. But what if there are models inside that model? I don't want to have to do
for i,v in pairs (Model:GetChildren()) do if v:IsA("Model") then for i,v in pairs (v:GetChildren()) do if v:IsA("Model") then for i,v in pairs (v:GetChildren()) do end end end
So is there any easier way to scan ALL the children of a model, including children inside models inside that model?
As JetCrusher said, recursion.
You can call a function inside a function, this will prove useful for the process.
function scan(item) --function right here, item is the item being scanned. --Stuff here. if #item:GetChildren() > 0 then --if anything is in it, then do the next thing. for _,v in pairs(item:GetChildren()) do --Loop through objects or descendants of 'item'. scan(v) --This will scan the objects inside of 'item' end --end loop end --end if then end --end function for _,v in pairs(workspace:GetChildren()) do --Go through all workspace elements. scan(v) --v will be scanned end