From what I know, they seem the exact same. They search through all of the descendants of the object until they find what they are looking for. Can anybody explain to me a scenario where you would use one over the other?
The IsDescendantOf function of Instance
returns a boolean
, meaning if the Instance
you are checking is the descendant of the other Instance
you specified, it will return true
, otherwise it will return false
.
FindFirstChild, specifically regarding its second parameter being true
, will return the Instance
that it is an ancestor of with the specified name or nil
if no such Instance
could be found.
I think the confusion you're getting is that you can use both A:FindFirstChild(B.Name, true)
and B:IsDescendantOf(A)
equivalently, but that's only true in conditional statements. The reason why A:FindFirstChild(B.Name, true)
will work in conditional statements is because Lua does not evaluate just boolean
statements in its conditionals but also truthy
and falsy
values. An Instance
that exists (and isn't nil
) is known to be truthy
, while an Instance
that does not exist (thus is nil
) is said to be falsy
. Hence, A:FindFirstChild(B.Name, true)
will evaluate pass a conditional, for an existing Instance
exists (in this case one whose name matches B.Name
).