Want to stay connected to the Scripting Helpers community and get real-time help? Join the Scripting Helpers Discord Server!
Ad
Log in to vote
2

What's the difference between FindFirstChild vs FindFirstChildWhichIsA?

Asked by 7 days ago

What's the difference between the two functions: FindFirstChild and FindFirstChildWhichIsA?

1 answer

Log in to vote
2
Answered by 7 days ago
Edited 7 days ago

FindFirstChild():

local child = script.Parent:FindFirstChild("Humanoid")

FindFirstChildWhichIsA():

local child = script.Parent:FindFirstChildWhichIsA("Humanoid")

The difference is that FindFirstChild() looks for an Instance with the given name while FindFirstChildWhichIsA() finds the Instance of a Class regardless of its name. Both methods can be used to find descendants and not just children like so:

local child1 = script.Parent:FindFirstChild("Humanoid", true)
local child2 = script.Parent:FindFirstChildWhichIsA("Humanoid", true)

What do we have here? The second parameter, a boolean, can be used to tell the method(s) to either find a child (false) or a descendant (true). Depending on what you are finding, finding a descendant is recommended.

0
the second parameter defaults to False, which means that it will only find a child and not a descendant. MCAndRobloxUnited 437 — 7d
0
Alright thank you this helps a ton! YabaDabaD0O 24 — 7d
Ad

Answer this question