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 4 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 — 4y
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 — 4y

1 answer

Log in to vote
0
Answered by
Thetacah 712 Moderation Voter
4 years ago
Edited by DeceptiveCaster 4 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 — 4y
0
Lol since when did objects have children? That's a joke. fredbeargamerbro563 0 — 4y
Ad

Answer this question