How do i stop an audio playing again before it ends

Hi, I’m currently making a Vehicle crash script for my Aircrafts and I have an issue where the audio plays before it ends.

This is the code I used for my Aircrafts:

Hitbox.Touched:Connect(function(hit)
	if Seat.Velocity.Magnitude >= 80 and hit then
		ImpactSoundSmall:Play()
		ImpactSoundBig:Play()
		ExplosionSmall:Emit(150)
		ExplosionBig:Emit(150)
		for i, part in pairs(script.Parent.Parent.Aircraft:GetChildren()) do
			part.Material = Enum.Material.Sandstone
			part.BrickColor = BrickColor.new("Dark stone grey")
		end
	end
end)

And this is what happened:

I tried using :Destroy() after but it still repeats so I’m trying to find an alternative.

You can simply do the following:

ImpactSoundSmall.PlayOnRemove = true
ImpactSoundBig.PlayOnRemove = true
ImpactSoundSmall:Destroy()
ImpactSoundBig:Destroy()

or if you wanna keep the sounds, use IsPlaying to check if it is already playing.

1 Like

use a debouce


local db = false

Hitbox.Touched:Connect(function(hit)
	if Seat.Velocity.Magnitude >= 80 and hit then
            if not db then
db = true
		ImpactSoundSmall:Play()
		ImpactSoundBig:Play()
		ExplosionSmall:Emit(150)
		ExplosionBig:Emit(150)
		for i, part in pairs(script.Parent.Parent.Aircraft:GetChildren()) do
			part.Material = Enum.Material.Sandstone
			part.BrickColor = BrickColor.new("Dark stone grey")
		end
task.wait("However much you want until the sound can play again")
db = false
	end
end
end)
1 Like

It didn’t work for me or I probably did it wrong…

The Cooldown worked fine. Thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.