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?
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
1 | local Part = game.Workspace.Part -- Target Part |
2 | local Child = Part:GetChildren() --Storing Table into var |
3 |
4 | if #Child = = 0 then |
5 | --Execute code |
6 | end |
This should work (I haven’t tested it, though)
1 | for _, v in ipairs (part:GetChildren()) do |
2 | if v then |
3 | print ( "There is a child!" ) |
4 | if not v then |
5 | print ( "There is no child" ) |
6 | end |