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

Sounds still play after model is destroyed?

Asked by
Galicate 106
7 years ago

I have this jammer model that plays static sounds when in distance, and i also have this script that breaks the jammer if shot at. Except the static sound keeps playing AFTER the model has been destroyed. I tried Sound:Stop() and Sound:Destroy() but neither of them worked.

01while true do
02    wait(0.1)
03if  script.Parent.Humanoid.Health < 100 then
04    script.Parent.Head.Break:Play()
05    script.Parent.Head.ParticleEmitter.Enabled = true
06    wait(0.1)
07    script.Parent.Head.ParticleEmitter.Enabled = false
08    script.Parent.Head.Static:Destroy()
09    wait(0.1)
10    script.Parent:Destroy()
11    break
12end
13end

2 answers

Log in to vote
0
Answered by 7 years ago

Try something like:

01while true do
02   wait(0.1)
03    if  script.Parent.Humanoid.Health < 100 then
04    script.Parent.Head.Break:Play()
05    script.Parent.Head.ParticleEmitter.Enabled = true
06    wait(0.1)
07    script.Parent.Head.ParticleEmitter.Enabled = false
08    script.Parent.Head.Static.PlaySoundOnRemove = false
09    script.Parent.Head.Static.Volume = 0
10    script.Parent.Head.Static:Stop()
11    script.Parent.Head.Static:Destroy()
12    wait(0.1)
13    script.Parent:Destroy()
14    break
15    end
16end

It's pretty hacky, but it should work.

0
Breaks the head but the rest of the model doesnt get destroyed Galicate 106 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Make sure you check the "PlayOnRemove" next time.

01script.Parent.Head:FindFirstChild("Break").PlayOnRemove=true
02while true do
03    wait(0.1)
04if  script.Parent.Humanoid.Health < 100 then
05    script.Parent.Head.Break:Play()
06    script.Parent.Head.ParticleEmitter.Enabled = true
07    wait(0.1)
08    script.Parent.Head.ParticleEmitter.Enabled = false
09    script.Parent.Head.Static:Destroy()
10    wait(0.1)
11    script.Parent:Destroy()
12    break
13end
14end

Answer this question