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?
FindFirstChild basically finds a child with a matching name you passed.
Yeah but why is that used? I can use normal pathing and it will work the same
FindFirstChild checks if exist that object on the parent
if exist returns the location of the object and if not just return nil
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.
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
And to iterate recursively over objects, to find the first descendant:
game.Workspace:FindFirstChild("Name", true)
It makes me wonder why there is a FindFirstDescendant
With FindFirstChild(), you can use variables.
Example: game.Workspace:FindFirstChild(Variable)
Thank you everyone I think I got it now