I wanna know the differences since they’re almost similar to me. Thanks!
Alright so basically the term
FindFirstChild() is like when you want the script to find it right away like so if everything is fully loaded in and you used findfirstchild to a part in workspace it would find it but if you use
WaitForChild() the script will wait for what your looking for incase it takes a bit to load in. If you need more help im here.
The difference between
:WaitForChild() are simple when you understand them.
:FindFirstChild(), if the child you are trying to find hasn't loaded in it wont be able to find them.
:WaitForChild() then function is somewhat alike the
WaitForChild() will stop the script until it has found the child in its parameters. When it finds the child, it will resume the script.
I hope this was helpful and you now have an understanding of
Some extra reading I would recommend would be: https://devforum.roblox.com/t/findfirstchild-and-waitforchild-addressing-common-bad-practices-and-habits-of-each/317491
:FindFirstChild() finds the first child of the name provided. It can be used to find childs with the same name or find a specific instance. If no child is found, nil is returned.
:WaitForChild() waits for a child with the name provided to be parented under the given parent. It can be used to prevent loading errors.
:WaitForChild() is equal to this function.
local function WaitForChild(parent, childName) while wait() do for i, child in pairs(parent:GetChildren()) do if child.Name == childName then return child end end end end
Note that the parent paramater isnt required for the built-in function itself.
WaitForChild() waits, won't register the target child until the code finds it. I use this for code that runs when the game starts or when something is cloned. That's when parts are loading and the child I'm looking for may not exist yet.
FindFirstChild() doesn't have this feature. If it doesn't find the target instance, even though it's loaded later, it will just pass and return nil.