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

How to find out is a part has no children?

Asked by 6 years ago

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

Log in to vote
0
Answered by
Fad99 286 Moderation Voter
6 years ago

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

1local Part = game.Workspace.Part -- Target Part
2local Child = Part:GetChildren() --Storing Table into var
3 
4if #Child == 0 then
5    --Execute code
6end
0
Thank you so much! DreamInspired 61 — 6y
0
Happy to help!! Fad99 286 — 6y
0
dude this will help me SO MUCH with my game. THANK YOU! speedyfox66 237 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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

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

Answer this question