How does FindFirstChildOfClass() work?

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)

1 Like

It finds the first child of an instance with the ClassName being strictly the passed class, while ignoring inheritance
image
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.

1 Like

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.

2 Likes

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.

2 Likes

FindFirstChild is used with names, while FindFirstChildOfClass and FindFirstChildWhichIsA is used with ClassNames, they aren’t the same.

1 Like

Thank both of y’all. I do appreciate your help.

I don’t know which post to mark as the solution honestly.

1 Like

No problem.

Mark the post that actually helped you as a solution.

1 Like