Checking for descendants

I found a pathfinding script a while back and it works great! Only issue is it uses a lot of unnecessary descendants (see image below), and I want to move all needed descendants (some of the nodes for the pathfinding are not needed) to a designated folder where I can utilize the needed nodes without fail.
image
How could I make a function or loop that goes through all the decsendants and only picks out the ones I need?
Thanks!

3 Likes

what type of instance are you trying to get?

1 Like

I’m just trying to get the parts that I need to make the completed path, I just need a function or loop to get all the descendants of a part and the descendents of that part etc. and filter the parts I need.

You can copy and paste this into command bar

for _, instance in pairs(Folder:GetDescendants) do --Replace "Folder" with the name of the folder your trying to get.

if instance.ClassName == "BasePart" then --Replace "BasePart" with the name of the class name.
instance.Parent = "Folder of choice"
end
end

Is there a way I can use this to loop through the descendants of a part and the descendants of that part etc in a script?

you can simply copy and paste the code the above into a script.

:GetDescendants already does that.
Don’t confuse it with :GetChildren()

I know of GetDescendents, my only issue is that it doesn’t cycle through every possible descendant unfortunately.

Could I get some help with this please? I really am struggling.

Nevermind, figured it out, just did some messing around with the pathfinding code.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.