can anyone explain FindFirstChildOfClass
? how does it actually work?
It returns the first child of an instance whose ClassName
matches the specified class name. If no matching child is found, it returns nil
.
Example:
:FindFirstChildOfClass("Humanoid")
This will find the first child that is a Humanoid. (It doesn’t accept names, only class names)
It finds the first child of an instance with the ClassName being strictly the passed class, while ignoring inheritance
workspace.stored:FindFirstChildOfClass("BasePart")
will return nil, as the ClassName of part is “Part”, it just inherits functions from BasePart, you would have to do workspace.stored:FindFirstChildOfClass("Part")
to actually get the part.
The only difference between this and FindFirstChildWhichIsA, is that this ignores inheritance.
So if I have 10 parts parented under workspace and then I typed workspace:FindFirstChildOfClass("Part")
, does that reference every Part
in the workspace? Or does it reference the first Part
in order?
No, it will only refer to the first Part it finds.
Last question.
Is it really that important or should I use FindFirstChild
instead?
If you want to look for specific class, use FindFirstChildOfClass
, if you want to look for specific instance with its name, use FindFirstChild
.
FindFirstChild is used with names, while FindFirstChildOfClass and FindFirstChildWhichIsA is used with ClassNames, they aren’t the same.
Thank both of y’all. I do appreciate your help.
I don’t know which post to mark as the solution honestly.
No problem.
Mark the post that actually helped you as a solution.