Need help adding a debounce in the function

Need help adding a debounce for both my sound and explosion in my function.

My current code isn’t working and I’m a little confused.
Here is my code:

--187137543
local mine = script.Parent
local minePosition = mine.CFrame.Position
local humanoid = game:GetService("Humanoid")
local sound = script.Parent.Sound
local DEBOUNCE = false


mine.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not DEBOUNCE then
		DEBOUNCE = true
		hit.Parent.Humanoid.Health = 0
		sound:Play()
		
		local boom = Instance.new("Explosion")
		boom.Visible = false
		boom.Parent = mine
		boom.Position = minePosition
		boom.BlastPressure = 30000
		boom.Visible = true
		DEBOUNCE = false
	end
end)
--187137543
local mine = script.Parent
local minePosition = mine.CFrame.Position
local humanoid = game:GetService("Humanoid")
local sound = script.Parent.Sound
local DEBOUNCE = false


mine.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not DEBOUNCE then
		DEBOUNCE = true
		hit.Parent.Humanoid.Health = 0
		sound:Play()
		
		local boom = Instance.new("Explosion")
		boom.Visible = false
		boom.Parent = mine
		boom.Position = minePosition
		boom.BlastPressure = 30000
		boom.Visible = true

        sound.Ended:Wait()
		DEBOUNCE = false
	end
end)
5 Likes

Wha- Thats it? what does it do? huhhh… That simple?

1 Like

It just waits for the sound to finish playing and then sets debounce to false.

2 Likes

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