Cooldown and disconect on unequip issue

Whenever i disconnet function on unequip the cooldown breaks due its in same function as attack and hitbox activation, but i have no idea how to handle cooldown and rest in 2 other functions to disconnect just attack one on unequip.

local tool = script.Parent
local players = game:GetService("Players")
local event = tool:WaitForChild("HitboxE")
local debounce = false
local hitboxAttach = tool.Handle.RigidConstraint
local Handle = tool:WaitForChild("Handle")
local AttackEvent 

tool.Equipped:Wait()
local char = tool.Parent
local hum = char:WaitForChild("Humanoid")
local plr = players:GetPlayerFromCharacter(char)
local animator = hum:WaitForChild("Animator")

local Idle = script.Idle
local WindupM11 = script["M1-1 windup"]
local M11 = script["M1-1"]
local Equip = script.Equip
local M11prehit = script.M11prehit

local LoadedEquip = animator:LoadAnimation(Idle)
local LoadedIdle = animator:LoadAnimation(Idle)
local LoadedM11 = animator:LoadAnimation(M11)
local LoadedM11Windup = animator:LoadAnimation(WindupM11)
local LoadedM11Prehit = animator:LoadAnimation(M11prehit)


tool.Equipped:Connect(function()
	
	hitboxAttach.Attachment1 = char:WaitForChild("HumanoidRootPart"):WaitForChild("HitboxAttachment")
	LoadedEquip:Play()
	LoadedEquip.Stopped:Wait()
	LoadedIdle:Play()
end)
local function attack ()
	if debounce == false then
		debounce = true
		LoadedM11Windup:AdjustSpeed(0.25)
		LoadedM11Windup:Play()
		LoadedM11Windup.Stopped:Wait()
		LoadedM11Prehit:Play()
		wait(0.25)
		LoadedM11Prehit:Stop()
		LoadedM11:Play()


		if tool.Parent == char then
			event:Fire()
		end





		task.wait(1)
		debounce = false



	end
end
	


tool.Unequipped:Connect(function()
    AttackEvent:Disconnect()
	LoadedEquip:Stop()
	LoadedIdle:Stop()
	LoadedM11:Stop()
	LoadedM11Windup:Stop()
	LoadedM11Prehit:Stop()
	
		

end)

AttackEvent = tool.Activated:Connect(attack)

I am having a hard time understanding the problem. Do you want the attack function to be re-connected when the tool is equipped? You could avoid disconnecting the tool.Activated function entirely since should only fire when equipped anyways.

I just wanted it to disconnect after u unequip but let cooldown still work

You can disconnect and use task.delay()

Sry for not replying earlier but wdym