Tool Debounce Not Working?

i have this hammer tool and there is this cooldown and when the cooldown ends the hammer can be used, but somehow after the cooldown i can click infinitely and the tool will activate, can somebody help me on this matter?

tool.Activated:Connect(function()
	if not db then db = true
		local character = tool.Parent
		local humanoid = character:WaitForChild("Humanoid")
		
		local animationTrack = humanoid:LoadAnimation(animation)
		animationTrack:Play()
		
		hitbox.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			humanoid:TakeDamage(15)
			handle.Hit:Play()
		end)
		
		animationTrack.Stopped:Wait()
		
		
	end
	wait(cooldown)
	db = false

end)

You could try this.

local LastUpdate = 0

tool.Activated:Connect(function()
	if os.time() - LastUpdate >= cooldown then
		LastUpdate = os.time()
		
		local character = tool.Parent
		local humanoid = character:WaitForChild("Humanoid")

		local animationTrack = humanoid:LoadAnimation(animation)
		animationTrack:Play()

		hitbox.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			humanoid:TakeDamage(15)
			handle.Hit:Play()
		end)

		animationTrack.Stopped:Wait()


	end
end)

Try this

tool.Activated:Connect(function()

	if db == false then
db = true

		local character = tool.Parent
		local humanoid = character:WaitForChild("Humanoid")
		
		local animationTrack = humanoid:LoadAnimation(animation)
		animationTrack:Play()
		
		hitbox.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			humanoid:TakeDamage(15)
			handle.Hit:Play()
		end)
		
		animationTrack.Stopped:Wait()
		
		wait(cooldown)
	db = false

	end

	

end)

try this:

tool.Activated:Connect(function()
	if not db then db = true
		local character = tool.Parent
		local humanoid = character:WaitForChild("Humanoid")
		
		local animationTrack = humanoid:LoadAnimation(animation)
		animationTrack:Play()
		
		hitbox.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			humanoid:TakeDamage(15)
			handle.Hit:Play()
		end)
		
		animationTrack.Stopped:Wait()
		
		
	end
	wait(cooldown)
	db = true

end)

is this the same script as mine

no, no, no. Look closer young one I changed db = false to db = true

can you explain what the difference is

In his code it sets the debounce to true at the end and that will make it where the tool will only work once.

oh ok, thank you for sharing :slight_smile:

1 Like

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