What is the benefit of:
Instance:FindFirstChild("childName")
vs
Instance.childName
?
I assume that if childName is not a child, the first will return nil while the other will throw an error?
What is the benefit of:
Instance:FindFirstChild("childName")
vs
Instance.childName
?
I assume that if childName is not a child, the first will return nil while the other will throw an error?
Instance.childname will cause a fatal script error if the child does not exist.
Instance:FindFirstChild("childname") will only return nil rather than breaking. Here's an example of the use:
if workspace:FindFirstChild("TestPart") then
print("part exists!")
else
print("part does not exist...")
end
If you merely used the former, this script would not work.
It does not return false, it returns nil
Apologies, forgot to fact check
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
It is used so that if the instance child does not exist it will make the value nil instead of giving and error and stopping the entire scripts. It's mainly used to check if the child is there or not.