Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Sounds still play after model is destroyed?

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

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.

1 comment

0

Breaks the head but the rest of the model doesnt get destroyed

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

This discussion is preserved as it was. New answers, comments, and votes are closed.