What are descendants and ancestors

What’s up devforum!

Sorry, if i am breaking any rules as this is my 3rd ever post.

So I kind of need help about what are descendants and what are ancestors. I’ve been searching all day long. But I can’t find any videos or articles about descendants and ancestors.

Problem:

What are descendants?
What are ancestors?

7 Likes

Descendants are like children, but they go all the way down the tree of children. Ancestors are like parents, but go all the way up the line of parents. If you had a model structured like so:

Model - “Tree” (parent to Workspace)
Part - “Branch” (parent to Tree)
Part - “Root” (parent to Branch)

If you had a script that said:

local tree branch = workspace.Tree:FindFirstChild("Branch")

this would return the “Branch” part. But you couldn’t do:

local tree branch = workspace.Tree:FindFirstChild("Root")

because the part named “Root” is a descendant of “Tree”. Not a direct child, but a child of a child. So instead, you could get it like this:

local tree branch = workspace.Tree:FindFirstDescendant("Root")

And this would return the part named “Root”.
you could do the same for ancestors.

TLDR a child is a child somewhere down the line of an object, rather than a direct child of an object, and same for ancestors. Ancestors are not the direct parent of an object, but somewhere up the line of parents.

Edit: The reason this is useful is because although working with ancestors/descendants can be laggy depending on what you are doing, lets say for example you wanted to make all Parts in the Workspace named “Door” have CanCollide = false.
If you made a script like so:

for _, p in pairs(workspace:GetChildren()) do
     if p:IsA("BasePart") and p.Name == "Door" then
          p.CanCollide = false
     end
end

This would only loop for BaseParts (Parts, meshparts, etc.) that their parents were directly workspace, but if you had models in the workspace, this script wouldnt target them because they werent direct children of game.Workspace. So to fix that you could use this instead:

for _, p in pairs(workspace:GetDescendants()) do
     if p:IsA("BasePart") and p.Name == "Door" then
          p.CanCollide = false
     end
end

Now the script would make every single Part named “Door” be able to be walked through if it was placed in the workspace, even if it was grouped in many models or folders! Although it would be more laggy, it would be the easiest and most efficient method to do this!

3 Likes

Descendants are not only the instance’s child, but THEIR children as well. An ancestor is an instance’s parent.

https://developer.roblox.com/en-us/api-reference/function/Instance/GetDescendants
https://developer.roblox.com/en-us/api-reference/function/Instance/FindFirstAncestor

I kind of feel like descendant and children and ancestor and parents are the same

Yeah. Sorry. I mixed up Descendant and Children lol. Take foodman54’s post instead.

1 Like

Also I don’t really got what isA() is

Descendants are every child of the object, every child of those children. Think of it like grandchildren. And I believe ancestors are the same as parents, I don’t really know.

1 Like

Here’s a simpler way to understand them:

Parent1, Parent2 and so on are ancestors.

Child1, Child2 and so on are descendants.

10 Likes

IsA returns true if the instance’s class is equivalent to the class you put in the function. For example, IsA(“Model”) will return “true” if the object is a model.

https://developer.roblox.com/en-us/api-reference/function/Instance/IsA

1 Like

Instance:IsA(“instanceType”) is a function that returns a boolean whether or not the specified Instance is equivalent to or a subclass of a given class which is instanceType; Just as what crossvallia said pretty much:
https://developer.roblox.com/en-us/api-reference/function/Instance/IsA

2 Likes

The aren’t descendants and children the same thing?

1 Like

actually no i don’t really get what ancestors are

1 Like

Now i kind of get what descendants are

1 Like

Thanks! I will watch a few tutorials on isA

1 Like

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