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

How do you check if a part or model has children?

Asked by 8 years ago
-- thing
    -- child

I'm not looking for a specific child I just want to check if a part even has one. So I want a true or false output

Ideas?

1 answer

Log in to vote
1
Answered by 8 years ago

roblox objects have a method called GetChildren() which basically returns a table with all the direct children of the object. Using table manipulation, we can tell if that table has 1 or more parts by using the # operator. The # operator basically returns the amount of elements in a table or the amount of characters in a string. So for example:

local Test = {"Apple", "Banana", "Carrot"}
print(#Test) --This prints 3

If you want to use this for what you want, basically just use the operator on the GetChildren() table, like so:

local Boolean = #Model:GetChildren() > 0
print(Boolean) --prints true if the model has 1 or more children, else it prints false

Hope this helped!

Ad

Answer this question