Most of you may think that I am simply talking about a generic for loop like so:
for i,v in pairs(workspace:GetChildren()) do
print(v.Name);
end
However, this will only iterate through every single child of workspace; what if I had a folder or a model containing more parts and objects? and what if I had a folder or another model inside of that folder/model with more objects? Essentially I am trying to figure out if there is a way to do a full loop over everything in the workspace, including all descendants of the workspace. i.e objects contained in a folder or model, and that folder/model is a child or descendant of the workspace. If anyone has a solution please let me know!

5 comments
That's called a recursive function, by the way.
thanks! Basically I am making a ROBLOX framework, and i need to be able to get all descendants and check that they are present in the initialization stage.
Iteration is also a viable option over recursion, for a deep recursive process can burn through a lot of memory assigning a new address to each level. This is the same reason you can get the infamous stack overflow error from infinite recursion.
I think there's a solution to that called "tail-end return". I could be mistaken, though.
I just hope people know to don't use global variables.