Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to remove all instances of GetChildren()?

Asked by 10 years ago

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

3 answers

Log in to vote
1
Answered by
Lacryma 548 Moderation Voter
10 years ago
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:

IsA

Class Reference

0
How could you know that. I thought you just fm. GetSporked 5 — 10y
0
Any proof of that? Lacryma 548 — 10y
0
just saying i think this guy knows more Chaserox 62 — 10y
Ad
Log in to vote
0
Answered by
ipiano 120
10 years ago

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
0
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 Chaserox 62 — 10y
0
GetChildren returns a list; you're looking for how to get rid of each item in a list ipiano 120 — 10y
0
Thank you i will try this Chaserox 62 — 10y
0
Still not working :( Chaserox 62 — 10y
0
nvm... im stupid Chaserox 62 — 10y
Log in to vote
0
Answered by
Syclya 224 Moderation Voter
6 years ago
local items = game:GetService("Workspace").Model

for _, v in pairs(items:GetChildren()) do
v:Destroy()
end

That should work just fine.

Answer this question