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 5 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
5 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

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

if #Child == 0 then
    --Execute code
end
0
Thank you so much! DreamInspired 61 — 5y
0
Happy to help!! Fad99 286 — 5y
0
dude this will help me SO MUCH with my game. THANK YOU! speedyfox66 237 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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 ```````````

Answer this question