Glorpia Docs
Scripting / Method

FindFirstChildOfClass()

Finds the first direct child whose ClassName exactly matches the requested class.

Syntax

instance:FindFirstChildOfClass(className)

Parameters and return value

NameTypeDescription
classNamestringExact ClassName to search for among direct children.
returnInstance or nilThe first matching direct child, or nil when no match exists.
This method searches direct children only. It does not have a recursive argument.

Example: find a Humanoid

Luau
script.Parent.Touched:Connect(function(hit)
    local character = hit.Parent
    local humanoid = character and character:FindFirstChildOfClass("Humanoid")

    if humanoid then
        humanoid.Health = 0
    end
end)

FindFirstChildOfClass vs IsA

FindFirstChildOfClass() compares the direct child's concrete ClassName. For example, searching for "BasePart" does not match a Part merely because Part:IsA("BasePart") is true.

Related