Swing animation cooldown not working

I Was Trying To Make A melee Using RaycastHitbox v4 but the swings cooldown doesnt work

local gibtype = “dismember”
–gib type :smiley: (dismember,bonebreak,blunt)
local howmanyswingsound = 3
local equipdelay = 2
local damage = 10
local headdamage = 19
—settings :point_up:
–DONT TOUCH ANYTHING UNDER HERE

local inspectanim
local char = script.Parent.Parent.Parent.Character
–local idle = char.Humanoid:LoadAnimation(script.Parent.Anims.idle)
local Self = script
local Mechanism = Self.Parent

local RaycastHitbox = require(game:GetService(“ReplicatedStorage”).RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(Mechanism)
local debounce = false
local DebugMode = game.ServerScriptService.Debug.Value

Hitbox.Visualizer = DebugMode

function inspect()
inspectanim = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Anims.Inspect)
inspectanim:Play()

end

Hitbox.OnHit:Connect(function(Hit)
if Hit.Parent ~= script.Parent.Parent then
if Hit.Parent:FindFirstChildOfClass(“Humanoid”) then
if gibtype == “dismember” then
if Hit.Name == “Head” then
Hit.Parent.Values.Jam.CutHead.Value = true
elseif Hit.Name == “Right Arm” then
Hit.Parent.Values.Jam.CutRightArm.Value = true
elseif Hit.Name == “Left Arm” then
Hit.Parent.Values.Jam.CutLeftArm.Value = true
elseif Hit.Name == “Right Leg” then
Hit.Parent.Values.Jam.CutRightLeg.Value = true
elseif Hit.Name == “Left Leg” then
Hit.Parent.Values.Jam.CutLeftLeg.Value = true
elseif Hit.Name == “Torso” then
Hit.Parent.Humanoid:TakeDamage(damage)–how many health
script.Parent.Handle.hit:Play()
end
elseif gibtype == “blunt” then
Hit.Parent.Humanoid:TakeDamage(damage)–how many health
script.Parent.Handle.hit:Play()
elseif gibtype == “bonebreak” then
if Hit.Name == “Head” then
Hit.Parent.Humanoid:TakeDamage(headdamage)–how many health
script.Parent.Handle.hit:Play()
elseif Hit.Name == “Right Arm” then
Hit.Parent.Humanoid:TakeDamage(headdamage)–how many health
script.Parent.Handle.hit:Play()
elseif Hit.Name == “Left Arm” then
Hit.Parent.Values.Other.LeftArmBone.Value = true
elseif Hit.Name == “Right Leg” then
Hit.Parent.Values.Other.RightLegBone.Value = true
elseif Hit.Name == “Left Leg” then
Hit.Parent.Values.Other.LeftLegBone.Value = true
elseif Hit.Name == “Torso” then
Hit.Parent.Humanoid:TakeDamage(damage)–how many health
script.Parent.Handle.hit:Play()
end
end
end
end
end)

function equip()
local anime = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Anims.Equip)
anime:Play()
script.Parent.Handle.Equip:Play()
debounce = false
task.wait(equipdelay)–equip time
debounce = true
end
function swing()
if debounce == true then
local anim = Mechanism.Parent.Humanoid:LoadAnimation(Mechanism.Anims.swing1)
local anim2 = Mechanism.Parent.Humanoid:LoadAnimation(Mechanism.Anims.swing2)
local swingsound = math.random(1,howmanyswingsound)–how many swing sounds
local animswing = math.random(1,2)
if animswing == 1 then
if anim2.IsPlaying == false then
anim:Play()
anim:GetMarkerReachedSignal(“HitStart”):Connect(function()
Hitbox:HitStart()
script.Parent.Handle.Trail.Enabled = true
Mechanism.Handle[“swing”… swingsound]:Play()
debounce = false
end)

  		anim:GetMarkerReachedSignal("HitEnd"):Connect(function()
  			Hitbox:HitStop()
  			debounce = true
  			script.Parent.Handle.Trail.Enabled = false
  		end)	
  		if typeof(inspectanim) == "Animation" then
  			inspectanim:Stop()	
  		end
  	end
  else  
  	if anim.IsPlaying == false then
  		anim2:Play()	
  		anim2:GetMarkerReachedSignal("HitStart"):Connect(function()
  			Hitbox:HitStart()
  			script.Parent.Handle.Trail.Enabled = true
  			Mechanism.Handle["swing".. swingsound]:Play()
  			debounce = false
  		end)

  		anim2:GetMarkerReachedSignal("HitEnd"):Connect(function()
  			Hitbox:HitStop()
  			debounce = true
  			script.Parent.Handle.Trail.Enabled = false
  			
  		end)
  		if typeof(inspectanim) == "Animation" then
  			inspectanim:Stop()	
  		end
  	end
  
  end	

end
end

function unequip()
end

script.Inspect.OnServerEvent:Connect(inspect)
script.Parent.Equipped:Connect(equip)
script.Parent.Activated:Connect(swing)
script.Parent.Unequipped:Connect(unequip)

I think you are using it the wrong way

local gibtype = "dismember"
--gib type :smiley: (dismember,bonebreak,blunt)
local howmanyswingsound = 3
local equipdelay = 2
local damage = 10
local headdamage = 19
--settings :point_up:
--DONT TOUCH ANYTHING UNDER HERE

local inspectanim
local char = script.Parent.Parent.Parent.Character
--local idle = char.Humanoid:LoadAnimation(script.Parent.Anims.idle)
local Self = script
local Mechanism = Self.Parent

local RaycastHitbox = require(game:GetService("ReplicatedStorage").RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(Mechanism)
local debounce = false
local DebugMode = game.ServerScriptService.Debug.Value

Hitbox.Visualizer = DebugMode

function inspect()
	inspectanim = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Anims.Inspect)
	inspectanim:Play()
end

Hitbox.OnHit:Connect(function(Hit)
	if Hit.Parent ~= script.Parent.Parent then
		if Hit.Parent:FindFirstChildOfClass("Humanoid") then
			if gibtype == "dismember" then
				if Hit.Name == "Head" then
					Hit.Parent.Values.Jam.CutHead.Value = true
				elseif Hit.Name == "Right Arm" then
					Hit.Parent.Values.Jam.CutRightArm.Value = true
				elseif Hit.Name == "Left Arm" then
					Hit.Parent.Values.Jam.CutLeftArm.Value = true
				elseif Hit.Name == "Right Leg" then
					Hit.Parent.Values.Jam.CutRightLeg.Value = true
				elseif Hit.Name == "Left Leg" then
					Hit.Parent.Values.Jam.CutLeftLeg.Value = true
				elseif Hit.Name == "Torso" then
					Hit.Parent.Humanoid:TakeDamage(damage)--how many health
					script.Parent.Handle.hit:Play()
				end
			elseif gibtype == "blunt" then
				Hit.Parent.Humanoid:TakeDamage(damage)--how many health
				script.Parent.Handle.hit:Play()
			elseif gibtype == "bonebreak" then
				if Hit.Name == "Head" then
					Hit.Parent.Humanoid:TakeDamage(headdamage)--how many health
					script.Parent.Handle.hit:Play()
				elseif Hit.Name == "Right Arm" then
					Hit.Parent.Humanoid:TakeDamage(headdamage)--how many health
					script.Parent.Handle.hit:Play()
				elseif Hit.Name == "Left Arm" then
					Hit.Parent.Values.Other.LeftArmBone.Value = true
				elseif Hit.Name == "Right Leg" then
					Hit.Parent.Values.Other.RightLegBone.Value = true
				elseif Hit.Name == "Left Leg" then
					Hit.Parent.Values.Other.LeftLegBone.Value = true
				elseif Hit.Name == "Torso" then
					Hit.Parent.Humanoid:TakeDamage(damage)--how many health
					script.Parent.Handle.hit:Play()
				end
			end
		end
	end
end)

function equip()
	local anime = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Anims.Equip)
	anime:Play()
	script.Parent.Handle.Equip:Play()
	debounce = true
	task.wait(equipdelay)--equip time
	debounce = false
end
function swing()
	if debounce == true then
		local anim = Mechanism.Parent.Humanoid:LoadAnimation(Mechanism.Anims.swing1)
		local anim2 = Mechanism.Parent.Humanoid:LoadAnimation(Mechanism.Anims.swing2)
		local swingsound = math.random(1,howmanyswingsound)--how many swing sounds
		local animswing = math.random(1,2)
		if animswing == 1 then
			if anim2.IsPlaying == false then
				anim:Play()
				anim:GetMarkerReachedSignal("HitStart"):Connect(function()
					Hitbox:HitStart()
					script.Parent.Handle.Trail.Enabled = true
					Mechanism.Handle["swing"][swingsound]:Play()
					debounce = true
				end)

				anim:GetMarkerReachedSignal("HitEnd"):Connect(function()
					Hitbox:HitStop()
					debounce = false
					script.Parent.Handle.Trail.Enabled = false
				end)
				
				if typeof(inspectanim) == "Animation" then
					inspectanim:Stop()	
				end
			end
		else  
			if anim.IsPlaying == false then
				anim2:Play()	
				anim2:GetMarkerReachedSignal("HitStart"):Connect(function()
					Hitbox:HitStart()
					script.Parent.Handle.Trail.Enabled = true
					Mechanism.Handle["swing".. swingsound]:Play()
					debounce = true
				end)

				anim2:GetMarkerReachedSignal("HitEnd"):Connect(function()
					Hitbox:HitStop()
					debounce = false
					script.Parent.Handle.Trail.Enabled = false
				end)
				if typeof(inspectanim) == "Animation" then
					inspectanim:Stop()	
				end
			end
		end	
	end
end

function unequip()
	
end

script.Inspect.OnServerEvent:Connect(inspect)
script.Parent.Equipped:Connect(equip)
script.Parent.Activated:Connect(swing)
script.Parent.Unequipped:Connect(unequip)

I Tried It Now It is Still Swings But If You Stop Swinging You cant Swing anymore and you can still spam swings
and also line 91 has error on the output

ti found the problem like you said i was using debounce wrong
i needed to make debounce false when the animation started
but instead i made it when hitstart event was reached

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