This kind of tree isn't the one with leaves and a stem, but a hierarchy of parent and child instances. I used a for loop to find what was in my designated point...
for _, v in pairs(game.Workspace:GetChildren()) do if v:IsA("Part") then print("Part found") end end
At that point I realized "Hey, I could make something that searches models!". My goal of that was to do the above script, but if it found a model start the process again but have that model as the search point.
local a = game.Workspace local b function Tree(location) loc = location:GetChildren() for _, v in pairs(loc) do if v:IsA("Part") then print("Part found") elseif v:IsA("Model") b = v Tree(b) end end for _, v in pairs(a:GetChildren()) do if v:IsA("Part") then print("Part found") elseif v:IsA("Model") b = v Tree(b) end end
What happens there is the process stops when it hits the model rather than seeing what's inside.
First of all there is some code that is not serving any purpose here...You were missing a then
on your elseif
and you were missing an end
.
function Tree(location) loc = location:GetChildren() for _, v in pairs(loc) do if v:IsA("Part") then print("Part found") elseif v:IsA("Model") then --Missing then Tree(v) end end --Missing end. end Tree(Workspace)