Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

What is the difference between DescendantAdded and ChildAdded? [closed]

Asked by
Yeevivor4 155
9 years ago

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.

Locked by DigitalVeer, Redbullusa, and M39a9am3R

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
2
Answered by 9 years ago

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 DescendantAddeddeals 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 ChildAddedbecause 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.

Ad
Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

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.