What does FindFirstChild do?

I have been scripting for some time now and I still doesnt know what is difference between normal pathing and FindFirstChild method. Can someone explain it to me?

6 Likes

FindFirstChild basically finds a child with a matching name you passed.

3 Likes

Yeah but why is that used? I can use normal pathing and it will work the same

2 Likes

FindFirstChild checks if exist that object on the parent
if exist returns the location of the object and if not just return nil

2 Likes

People mainly use it for searching instances that are possibly haven’t been created yet. The difference with this and normal pathing is if the instance cannot be found, the method will return nil, normal pathing produces an error. But, FindFirstChild is 70 percent slower than normal pathing.

4 Likes

FindFirstChild (like what people said) Is Used to look for objects under a specific name, if found the script play out as normal depending on the condition setup, it not found, FindFirstChild is returned nil

Example:

Part.Touched:Connect(function(part)
   local Humanoid = part.Parent:FindFirstChild("Humanoid") -- Attempts to look for a Humanoid
   if Humanoid then -- if Humanoid returns a "Humanoid"
      print("Found a Human!")
   end
end)

FindFirstChildOfClass looks for something under a Class, nearly (if not) identical to FindFirstChild

FindFirstChildWhichIsA Respects the inheritance of the Instance, Its is pretty much a way of Using Ex:IsA()


To put it simply

  • FindFirstChild finds the first object by name
  • FindFirstChildOfClass finds the first object by Class
  • FindFirstChildWhichIsA finds the first object by Inheritance

FindFirstChild
FindFirstChildOfClass
FindFirstChildWhichIsA

Instance: functions


6 Likes

And to iterate recursively over objects, to find the first descendant:

game.Workspace:FindFirstChild("Name", true)
6 Likes

It makes me wonder why there is a FindFirstDescendant

6 Likes

With FindFirstChild(), you can use variables.
Example: game.Workspace:FindFirstChild(Variable)

4 Likes

Thank you everyone I think I got it now