Getting the Head parent of all parents

Basically, i want to get the head of all parents in the folder, no matter how many parents there in the way.

image

This is the example, and i am trying to check if the head parent of all parent == “Folder”
I dont want my script to look something like that:

if Part.Parent.Name == "Folder" or  Part.Parent.Parent.Name == "Folder" or Part.Parent.Parent.Parent.Name == "Folder" or Part.Parent.Parent.Parent.Parent.Name == "Folder" or Part.Paren.Parent.Parent.Parent.Parent.Name == "Folder" or Part.Parent.Parent.Parent.Parent.Parent.Name == "Folder" then

end

Is there any way i can do that?

Use IsDescendantOf(). It’s probably not great to have so many parts inside of parts…

local folder = --path to folder here

if part:IsDescendantOf(folder) then
    print("yay it's a descendant of the folder")
end

And if you want to get all the items in the folder and check if they are parts, you could just iterate.

1 Like

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