So I have a doughnut machine, and the doughnuts are grouped for easier management. When the donuts are deleted, the group that holds them does not, which could probably lag servers after a few runs, how can I fix this without deleting donut groups that have donuts in them?
EDIT: Forgot to mention I want to check each D1 group for children (as shown in gif) and not just the main group so I can delete groups without children that are in the main group.
You can use an if statement as simple as this to check if an Instance has children.
if #instance:GetChildren() == 0 then -- // If there are NO children end
To check if a model has no children, then you can simply do:
local children = model:GetChildren() if #children >= 1 then print('it has children') else print('it doesnt') end
local checkChildren = coroutine.wrap(function() while wait(1) do for _,model in pairs(directory_to_the_parent_of_models:GetChildren()) do --// Change this to the path to the parent of all the models if #model:GetChildren() < 1 then print(#model:GetChildren()) else print("No Children") end end end end) checkChildren() --// I made this a Coroutine so it runs in a new thread and doesn't stop any other code from being stopped with this while loop.
This will repeatedly loop through all the models in the model to check if it has 0 children or more than 0 children.
You could make this a function and call it whenever you want and customize it to look fancy or whatever you want.
Hope this helped! Feel free to select this as an answer if this helped you!