Weapon cooldown while animation playing

Currently trying to make it so, that when you using weapon and it plays ‘attack’ animation there will be a cooldown until person will able to attack next time.

Adding wait() didn’t helped. I guess it’s been used wrong or something like that. No clue.

script.Parent.Activated:connect(function()
    d = b:LoadAnimation(script.Parent.LeftSlash)
    d:Play()
    script.Parent.Top["Swing"]:Play()
    local dmg =    script.Parent.Top.Touched:connect(function(a)
        if a.Parent:FindFirstChild("Humanoid") then
                a.Parent.Humanoid:TakeDamage(2.5)
                script.Parent.Top["Hit"]:Play()
        end
    end)
    wait(.2)

end)

You need to use a debounce, example:

local Debounce = false
script.Parent.Activated:connect(function()
	if not Debounce then
		Debounce = true
		d = b:LoadAnimation(script.Parent.LeftSlash)
		d:Play()
		script.Parent.Top["Swing"]:Play()
		local dmg =    script.Parent.Top.Touched:connect(function(a)
			if a.Parent:FindFirstChild("Humanoid") then
				a.Parent.Humanoid:TakeDamage(2.5)
				script.Parent.Top["Hit"]:Play()
			end
		end)
		wait(.2)
		Debounce = false
	end
end)
1 Like