How do I add a cooldown to this gun whip script?

I can keep on spamming V to keep bashing and it’s OP, but I don’t know how to add a cooldown cause I’m a bad scripter… help? (the damaging part is in another script.)

Code:

local Player = game.Players.LocalPlayer


Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Character:WaitForChild("Humanoid")

local bash = false

bashAnimation = Humanoid:LoadAnimation(script:WaitForChild("BashHit"))

script.Parent.Equipped:connect(function(mouse)

	mouse.KeyDown:connect(function(key)
		key = key:lower()
		if key == "v" then
			
			script.Parent.Handle.StockBash:Play()
			bashAnimation:Play()
			
			
			
		end
	end)
end)

You need to “debounce” the mouse by adding a wait and some true/false logic.
This article has everything you need to get started:

1 Like