How can i add a hit cooldown with debounce?

Code:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Button1Down = mouse.Button1Down
local Players = game:GetService(“Players”)
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character

    mouse.Button1Down:Connect(function(swing1)
    	local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.animation)	
    	animation:Play()
    end)

Basically trying to add a cooldown the before you can swing again

1 Like

You could do something like this

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local mouse = LocalPlayer:GetMouse()
local Character = LocalPlayer.Character

local animation = Character:WaitForChild("Humanoid").Animator:LoadAnimation(script.Parent.animation)

local deb = false

mouse.Button1Down:Connect(function(swing1)
	if deb then return end
	deb = true
	animation:Play()
	wait(1)
	deb = false
end)

thanks for help used something similar inspired me alot for debounce

3 Likes