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

How to destroy all parts in a model when something touches it?

Asked by 10 years ago

I tried doing this:

1parts=script.Parent:GetChildren()
2parts.Touched:connect(Clean)
3 
4function Clean(Part)
5      wait(4)
6      parts:Destroy()
7end

(the parts are within a model)

1 answer

Log in to vote
3
Answered by 10 years ago

Here we go.

For Loop

With the for loop, we can do this.

1for i,v in pairs(script.Parent:GetChildren()) do
2    wait()
3    v.Touched:connect(function(hit)
4        print("boom boom bam explosion destroys")
5        script.Parent:Destroy()
6    end)
7end
0
That for loop doesn't quite fit in to this. Try showing him the link to the for pairs. woodengop 1134 — 10y
Ad

Answer this question