What Is An Ancestor?

Hello! I don’t understand what is an ancestor. Is an ancestor a descendant’s child? EG:

game -- Parent
Workspace -- Child
Folder -- Descendant
Part -- Ancestor

Is this correct? Thanks! :wave:

1 Like

An Ancestor of an object is a parent or higher. So for example you could do:


if part:FindFirstAncestor("item") then
1 Like

An ancestor is like a part’s parent’s parent:

image

Think about IRL ancestry, as Roblox has their naming scheme similar to such:

  • You are the child of a parent. Your are your dad’s child, your dad is your parent.
  • Your grandpa is an ancestor. So is your great-grandpa, and your great-great-grandpa.
  • You are your grandpa’s descendant. You are your great-grandpa’s descendant, and your great-great-grandpa’s descendant.

Same applies to Roblox. Think of it this way:

Game -- Ancestor of everything
Workspace -- Child of game, descendant of game, ancestor of part
ReplicatedStorage -- Child of game, descendant of game
Part -- Child of workspace, descendant of workspace, descendant of Game

Hope this helps!

8 Likes

I suppose you can think of an Ancestor like the opposite of .Parent lol

It goes the other way, & provided you’re able to access its objects & childs/parents you could check for that specific object:

local Folder = workspace.Folder1.Folder2 --We have 2 Folders parented inside the 

if Folder:FindFirstAncestor("Folder1") then --This would check if Folder2 is a parent is Folder1
    print("Yes")
end

--While this...
if Folder:FindFirstChild("Folder1") then --This would check if Folder2 is a child of Folder1, which would not work
    print("Yes v2")
end

Oh I see. So would this be correct:

Grandparents -- Ancestor
Parents -- Parent
Child -- Child
Part -- Descendant

??

So basically, an ancestor is a the parent of a parent?

Well, its is indeed correct !

Parents are also ancestors and children are also descendants. An ancestor is anything above, including a direct parent. A descendant is anything below, including a child.

Roblox’s OOP (and all other OOP’s that I know of) use the hierarchical data model for functioning. It is a data model which is layered in multiple levels. A Child of an object is any other object that is exactly 1 level below the former object. A Parent of an object is any other object that is exactly 1 level above the former object. A Descendant of an object is any object that is below the former object; the number of levels can be any. An Ancestor of an object is any object that is above the former object; the number of levels can be any. A Sibling of an object is any object that is in the same level as the former object. This can be represented graphically as below:

For instance, workspace is the parent of Part-A,Character and Baseplate , but it is not a parent of Surface GUI or game . However, it is a Child of game and an Ancestor of SurfaceGUI . Local script is a Descendant of game,workspace,part-a,surfaceGui,Frame and Text Button . Local Script and String Value are both Siblings of each other.

For further information about Hierarchical Data Model, visit the Wikipedia page.

1 Like

That’s correct.

An ancestor is a parent of a parent. Or maybe, a parent-parent-parent. It can go for quite a bit, but yes!

1 Like