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

How does findFirstChild() know which child is first?

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

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.

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.

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