Iv'e begun creating a mine but I don't want to destroy the model straight after its stood one, I want to let the sound finish playing before I Destroy the mine. I thought of making the parts transparent until the sound is finished and then destroying the model as a whole.
01 | local de = false -- Debounce |
02 |
03 | local mine = script.Parent.Parent -- Defining the model |
04 |
05 | local descendants = mine:GetDescendants() -- I could use GetChildren |
06 |
07 | script.Parent.Touched:Connect( function (hit) |
08 | local h = hit.Parent:FindFirstChild( "Humanoid" ) |
09 | if h ~ = nil and de = = false then |
10 | de = true |
11 | local e = Instance.new( "Explosion" ) |
12 | e.Parent = script.Parent |
13 | e.Position = script.Parent.Position |
14 | script.Explosion:Play() |
15 | for i = 1 ,#descendants do |
Any help would be appreciated
01 | local de = false -- Debounce |
02 |
03 | local mine = script.Parent.Parent -- Defining the model |
04 |
05 | local children = mine:GetChildren() -- GetChildren() is another way of getting all parts in a model. |
06 |
07 | script.Parent.Touched:Connect( function (hit) |
08 | local h = hit.Parent:FindFirstChild( "Humanoid" ) |
09 | if h ~ = nil and de = = false then |
10 | de = true |
11 | local e = Instance.new( "Explosion" ) |
12 | e.Parent = script.Parent |
13 | e.Position = script.Parent.Position |
14 | script.Explosion:Play() |
15 | for _, v in pairs (children) do -- Using a for loop to get the objects inside the object. |
use loops like
this
1 | for i, v in pairs (game.Workspace.Model:GetChildren()) do |
2 | -- your code |
3 | end |