Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to check if an object has children?

Asked by 5 years ago

How can I check if an object has children in it?

0
Depends what you're trying to do...there's GetChildren(), DescendantAdded, etc. ABK2017 406 — 5y
0
If #Object:GetChildren() > 0 than the object has children. print( #object:GetChildren() > 0 and "Object has children" or "Object does not have children" ) --> 'object' is pseudo-code. pidgey 548 — 5y

1 answer

Log in to vote
0
Answered by
Thetacah 712 Moderation Voter
5 years ago
Edited by DeceptiveCaster 5 years ago

You could create a table of the objects children by using the GetChildren() method, and then see if the table has more than 0 values...Which would mean there is children

EXAMPLE(lets say you want to figure out if a part named "Part" in the workspace has children):

local part = workspace.Part

partTable = part:GetChildren()
if #partTable >0 then
    print("Object has at least one child")
end

0
thx realmadrid02 8 — 5y
0
Lol since when did objects have children? That's a joke. fredbeargamerbro563 0 — 5y
Ad

Answer this question