Hello im wondering on how i would get rid of all instances of get children im making a sort of cleaning script.
i tried using :Remove() and :Destroy() but it popped up with an error
local object = workspace for i,v in pairs(object:GetChildren()) do v:Destroy() end
Now this deletes everything in the specified object. If you want to delete a specific type of class then you would need to specify that as well using the IsA method that returns whether an instance is a specific class.
An example would be:
local object = workspace for i,v in pairs(object:GetChildren()) do if v:IsA("Hat") then v:Destroy() end end
Read more:
Try setting the variable that you used to nil, I believe once nothing is referencing the list, it will disappear; I've never heard of need to do manual garbage collection in Roblox.
list = Model:GetChildren() for...end list = nil
Also, if you're really worried about script/game speed use local variables if you can.
---Edit, after some comment discussion
If you want to remove all items in a list, which is what you get from GetChildren() then use a for loop to look through it
list = Model:GetChildren() for i=1, #list do list[i]:Remove() end
local items = game:GetService("Workspace").Model for _, v in pairs(items:GetChildren()) do v:Destroy() end
That should work just fine.