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

How does findFirstChild() know which child is first?

Asked by 6 years ago

I know it finds the first child of the name, but what is the first child? Is there a list of children that I don't know about, and it finds the first one on that list? Does it magically know which child I want? Am I overthinking this? I need your help!

2 answers

Log in to vote
0
Answered by
IcyEvil 260 Moderation Voter
6 years ago
Edited 6 years ago

It knows which child you want, because

findFirstChild('ItemHere')

You literally tell it the exact name of the item you want, I suppose if there are multiples of the same item with the same name, then it wouldn't know, so be specific when naming parts, and groups.

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

findFirstChild is equivalent to the following code:

function obj:findFirstChild(name)
    for _,v in pairs(obj:GetChildren()) do
        if v.Name == name then
            return v
        end
    end
    return false
end

Basically, it looks through the object's children then returns the first one it finds with the matching name. There is no specific one that it will return, unless there is only ONE object named as such.

Answer this question