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
6 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.

while true do
    wait(0.1)
if  script.Parent.Humanoid.Health < 100 then
    script.Parent.Head.Break:Play()
    script.Parent.Head.ParticleEmitter.Enabled = true
    wait(0.1)
    script.Parent.Head.ParticleEmitter.Enabled = false
    script.Parent.Head.Static:Destroy()
    wait(0.1)
    script.Parent:Destroy()
    break
end
end

2 answers

Log in to vote
0
Answered by 6 years ago

Try something like:

while true do
   wait(0.1)
    if  script.Parent.Humanoid.Health < 100 then
    script.Parent.Head.Break:Play()
    script.Parent.Head.ParticleEmitter.Enabled = true
    wait(0.1)
    script.Parent.Head.ParticleEmitter.Enabled = false
    script.Parent.Head.Static.PlaySoundOnRemove = false
    script.Parent.Head.Static.Volume = 0
    script.Parent.Head.Static:Stop()
    script.Parent.Head.Static:Destroy()
    wait(0.1)
    script.Parent:Destroy()
    break
    end
end

It's pretty hacky, but it should work.

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

Make sure you check the "PlayOnRemove" next time.

script.Parent.Head:FindFirstChild("Break").PlayOnRemove=true
while true do
    wait(0.1)
if  script.Parent.Humanoid.Health < 100 then
    script.Parent.Head.Break:Play()
    script.Parent.Head.ParticleEmitter.Enabled = true
    wait(0.1)
    script.Parent.Head.ParticleEmitter.Enabled = false
    script.Parent.Head.Static:Destroy()
    wait(0.1)
    script.Parent:Destroy()
    break
end
end

Answer this question