Say I have a table of parts in the same folder which parents more parts inside of them like a tree hierarchy. Each part has an "enabled" value which tells the function to stop recursion at that point. My function is supposed to loop through every point in this hierarchy top-down, and only stopping if the "enabled" value is false.
My attempt seems to work at first, but in the first for loop it only recurses on the first element and then it stops recursion right there and only continues on the first elements of the tree hierarchy. I can't think of any logic statements to fix this. I tried using spawn but I feel like that method is too hacky. Any tips?
function recurse(highestParentParts)
for i,v in pairs(highestParentParts:GetChildren()) do
if v:IsA("BasePart") and v:FindFirstChild("Enabled") and v.Enabled.Value == true then
recurse(v) -- The top recursion never moves on to i=2, i=3, etc
end
end
end
