Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is the difference between DescendantAdded and ChildAdded?

Hi, I had a question about this. What is the difference between these two? If they have the same basic function, how come the two was added? Is there a difference between the words "Child" and "Descendant"?

~Thank you for reading, and/or answering.

2 answers

✓ Accepted answer

One Deals With Direct Children and One Deals With Children In Any Form Of Hierarchy.

ChildAdded only deals with a hierarchy directly under the object while DescendantAdded deals with a form of child added to the hierarchy.

For example, let's take a look at an example:

workspace.ChildAdded:connect(function(obj)
	print(obj.Name)
end)

workspace.DescendantAdded:connect(function(obj)
	print(obj.Name)
end)

s = Instance.new("Part")
s.Name = "Steve"
s.Parent = workspace
bob = s:Clone()
bob.Name = "Bob"
bob.Parent = s

The model structure of this looks like the following:

-Workspace

Bob [Under Workspace]

Steve [ Under Bob]

The following code will print:

Steve

Steve

Bob

The Steve's name is printed twice because it is a direct child of Workspace, thus DescendantAdded and ChildAdded both detect it.

However, Bob's name is only printed once from DescendantAdded and not from ChildAdded because it's not a direct child but is yet in the hierarchy.

REAL LIFE ANALOGY:

Let's say Family Tracking Company 1 is ChildAdded and Family Tracking Company 2 is DescendantAdded;

If John And Mary Had A Child Named "Steve"[I won't tell you the process of how a child is made]:

Both Company 1 and Company 2 would recognize "Steve" and track him. However, say "Steve" and a girl named "@sera plz" had a baby and the babies name was "DigitalVeer":

Company 1 wouldn't track that baby as it is a 'grandchild' and not a direct child but Company 2 would.

This is just answering your third question.

Let's say you have a BasePart inside of a model, which is inside of game.Workspace.

-game

	-Workspace

		-Model

			-Part

Workspace would be a child of game.

Model would be a descendant of game.

Part would be a descendant of game.

Part would be a child of Model.

Child - An object that's right below the hierarchy of what you're referring to.

Descendant - An object that's ANYWHERE below the hierarchy of what you're referring to.

This discussion is preserved as it was. New answers, comments, and votes are closed.