Cooldown making tool fire only one time

My tool is only firing after I added the cooldown, I tried changing the cooldown position but didn’t work, help pls

local Equipped = false
local CombaTOOL = script.Parent
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")

local Player = game.Players.LocalPlayer
local Char = Player.CharacterAdded:Wait()
local Hum = Char:WaitForChild("Humanoid")

local Combo = 1
local CD = false

CombaTOOL.Equipped:Connect(function()
	Equipped = true
	
end)

CombaTOOL.Unequipped:Connect(function()
	Equipped = false
	
end)

UIS.InputBegan:Connect(function(Input, GameProcessed)
	if Equipped then
		if Input.UserInputType == Enum.UserInputType.MouseButton1 and CD == false then
			CD = true
			
			RS.CRemote:FireServer()
			print("!!!")
			
			if Combo == 1 then
				local RightPunch = Hum:WaitForChild("Animator"):LoadAnimation(CombaTOOL.RightPunch)
				RightPunch:Play()
				Combo = 2
				
			elseif Combo == 2 then
				local LeftPunch = Hum:WaitForChild("Animator"):LoadAnimation(CombaTOOL.LeftPunch)
				LeftPunch:Play()
				Combo = 1
				
			wait(0.5)
			CD = false
		
			end
		end
	end
end)

You are only setting cooldown to false if it’s the Combo 2. Maybe that is the problem?

You put the CD = false inside the elseif Combo == 2. Since you set the Combo value to 1, it wont change the cooldown to false.

Move it outside instead.

       elseif Combo == 2 then
			local LeftPunch = Hum:WaitForChild("Animator"):LoadAnimation(CombaTOOL.LeftPunch)
			LeftPunch:Play()
			Combo = 1
	
		end
	
		wait(0.5)
		CD = false

The format of the topic was wrong, fixed it now

That was because I formatted the topic wrong, now it’s properly formatted

The CD is only being set to false in Combo 2. Set it to false in combo 1 and it should fix the issue.

local Equipped = false
local CombaTOOL = script.Parent
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")

local Player = game.Players.LocalPlayer
local Char = Player.CharacterAdded:Wait()
local Hum = Char:WaitForChild("Humanoid")

local Combo = 1
local CD = false

CombaTOOL.Equipped:Connect(function()
	Equipped = true
	
end)

CombaTOOL.Unequipped:Connect(function()
	Equipped = false
	
end)

UIS.InputBegan:Connect(function(Input, GameProcessed)
	if Equipped then
		if Input.UserInputType == Enum.UserInputType.MouseButton1 and CD == false then
			CD = true
			
			RS.CRemote:FireServer()
			print("!!!")
			
			if Combo == 1 then
				local RightPunch = Hum:WaitForChild("Animator"):LoadAnimation(CombaTOOL.RightPunch)
				RightPunch:Play()
				Combo = 2

                                wait(0.5)
                                CD = false
				
			elseif Combo == 2 then
				local LeftPunch = Hum:WaitForChild("Animator"):LoadAnimation(CombaTOOL.LeftPunch)
				LeftPunch:Play()
				Combo = 1
				
			wait(0.5)
			CD = false
		
			end
		end
	end
end)
1 Like

This made it work 2 times XD

I put it just downside the CD true and now it’s working ty

local Equipped = false
local CombaTOOL = script.Parent
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")

local Player = game.Players.LocalPlayer
local Char = Player.CharacterAdded:Wait()
local Hum = Char:WaitForChild("Humanoid")

local Combo = 1
local CD = false

CombaTOOL.Equipped:Connect(function()
	Equipped = true
	
end)

CombaTOOL.Unequipped:Connect(function()
	Equipped = false
	
end)

UIS.InputBegan:Connect(function(Input, GameProcessed)
	if Equipped then
		if Input.UserInputType == Enum.UserInputType.MouseButton1 then
			if CD == false then
				CD = true
				
				wait(0.5)
				CD = false
			
				RS.CRemote:FireServer()
				print("!!!")
				
				if Combo == 1 then
					local RightPunch = Hum:WaitForChild("Animator"):LoadAnimation(CombaTOOL.RightPunch)
					RightPunch:Play()
					Combo = 2
					
				elseif Combo == 2 then
					local LeftPunch = Hum:WaitForChild("Animator"):LoadAnimation(CombaTOOL.LeftPunch)
					LeftPunch:Play()
					Combo = 1

				end
			end
		end
	end
end)

Wait, but now you will punch AFTER 0.5 seconds. you should put the 0.5 wait after it.

local Equipped = false
local CombaTOOL = script.Parent
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")

local Player = game.Players.LocalPlayer
local Char = Player.CharacterAdded:Wait()
local Hum = Char:WaitForChild("Humanoid")

local Combo = 1
local CD = false

CombaTOOL.Equipped:Connect(function()
	Equipped = true
	
end)

CombaTOOL.Unequipped:Connect(function()
	Equipped = false
	
end)

UIS.InputBegan:Connect(function(Input, GameProcessed)
	if Equipped then
		if Input.UserInputType == Enum.UserInputType.MouseButton1 then
			if CD == false then
				CD = true
			
				RS.CRemote:FireServer()
				print("!!!")
				
				if Combo == 1 then
					local RightPunch = Hum:WaitForChild("Animator"):LoadAnimation(CombaTOOL.RightPunch)
					RightPunch:Play()
					Combo = 2
					
				elseif Combo == 2 then
					local LeftPunch = Hum:WaitForChild("Animator"):LoadAnimation(CombaTOOL.LeftPunch)
					LeftPunch:Play()
					Combo = 1

				end

                                wait(0.5)
                                CD = false
			end
		end
	end
end)

this SHOULD work better, tell me if it doesnt

Ooh, this seems to work better, TY

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