Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to find out is a part has no children?

I am trying to make an if statement, where the argument is that a part has no children Ex:

if (part has no children) then (insert code here)

How would I attempt this?

2 answers

✓ Accepted answer

You would get a table of the children of that part and see if there are 0 values in that table, so then you can execute your code

local Part = game.Workspace.Part -- Target Part
local Child = Part:GetChildren() --Storing Table into var

if #Child == 0 then
    --Execute code
end

3 comments

0

Thank you so much!

0

Happy to help!!

0

dude this will help me SO MUCH with my game. THANK YOU!

This should work (I haven't tested it, though)

for _, v in ipairs (part:GetChildren()) do
if v then
print("There is a child!")
if not v then
print("There is no child")
end

This discussion is preserved as it was. New answers, comments, and votes are closed.