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
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
what i have currently is 3 cards get generated. but when i hit Replay the cards stay.. i need a script that will remove the cards each card is named "Card" so i assumed getchildren would be the easiest way
GetChildren returns a list; you're looking for how to get rid of each item in a list
Thank you i will try this
Still not working :(
nvm... im stupid
local items = game:GetService("Workspace").Model
for _, v in pairs(items:GetChildren()) do
v:Destroy()
end
That should work just fine.
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
How could you know that. I thought you just fm.
Any proof of that?
just saying i think this guy knows more