Why wont my cooldown work?

I’ve made a cooldown for a move and to use the move you have to double tap w I made a debounce cool down for the move but it doesn’t work and on top of that if you keep holding down w it repeats the move multiple times how could I fix this? Code:

local function CheckSpecialFlight()
	local wTbl = flightControls.W
	local currentWVel = vel[wTbl.Axis] * wTbl.VelSign
	if (not latching) then
		if keysDown.DoubleW and keysDown.W and rushDeb == false then
		
			RushVfx(char, team, lockedTarget)
			rds.Remotes.Flight:FireServer("rush", lockedTarget)
			task.wait(settingsModule.RushDelay)
			local doubleWTbl = flightControls.DoubleW
			local disfrom = (plr.Character.HumanoidRootPart.Position - lockedTarget.HumanoidRootPart.Position).Magnitude
			if disfrom <= 100 then
			elseif disfrom > 100  then return end
			plr.Character.HumanoidRootPart.CFrame = lockedTarget.HumanoidRootPart.CFrame *  CFrame.new(-6,0,0)
			-- adding same effect after teleporting
			local Rushit_sound = game.ReplicatedStorage.Assets.SFX.RushHit
			Rushit_sound:Play()

			local function RushVfx(vfxChar, vfxTeam, enemyVfxChar)

				local vfxHrp = vfxChar:FindFirstChild("HumanoidRootPart")
				local enemyVfxHrp = enemyVfxChar:FindFirstChild("HumanoidRootPart")
				if vfxHrp and enemyVfxHrp then

					local cf = CFrame.lookAt(vfxHrp.Position, enemyVfxHrp.Position) * CFrame.new(0, 0, -4)
					local rushVfxPart = rds.Assets.VFX.RushVfx_new:Clone()
					rushVfxPart.CFrame = cf
					rushVfxPart.Parent = workspace.Debris
					EmitParticles(rushVfxPart)
					dbs:AddItem(rushVfxPart, 1.5)
				end
			end
		end
		rushDeb = true
		playRushAnim = true
		keysDown.DoubleW = false
		rushReached = false
	task.delay(settingsModule.RushCooldownDuration, function()
		
		rushDeb = false
		
		end)

Try this , let me know if it is still not working

local function CheckSpecialFlight()
	local wTbl = flightControls.W
	local currentWVel = vel[wTbl.Axis] * wTbl.VelSign
	if (not latching) then
		if keysDown.DoubleW and keysDown.W and rushDeb == false then
		
			RushVfx(char, team, lockedTarget)
			rds.Remotes.Flight:FireServer("rush", lockedTarget)
			task.wait(settingsModule.RushDelay)
			local doubleWTbl = flightControls.DoubleW
			local disfrom = (plr.Character.HumanoidRootPart.Position - lockedTarget.HumanoidRootPart.Position).Magnitude
			if disfrom <= 100 then
			elseif disfrom > 100  then return end
			plr.Character.HumanoidRootPart.CFrame = lockedTarget.HumanoidRootPart.CFrame *  CFrame.new(-6,0,0)
			-- adding same effect after teleporting
			local Rushit_sound = game.ReplicatedStorage.Assets.SFX.RushHit
			Rushit_sound:Play()

			local function RushVfx(vfxChar, vfxTeam, enemyVfxChar)

				local vfxHrp = vfxChar:FindFirstChild("HumanoidRootPart")
				local enemyVfxHrp = enemyVfxChar:FindFirstChild("HumanoidRootPart")
				if vfxHrp and enemyVfxHrp then

					local cf = CFrame.lookAt(vfxHrp.Position, enemyVfxHrp.Position) * CFrame.new(0, 0, -4)
					local rushVfxPart = rds.Assets.VFX.RushVfx_new:Clone()
					rushVfxPart.CFrame = cf
					rushVfxPart.Parent = workspace.Debris
					EmitParticles(rushVfxPart)
					dbs:AddItem(rushVfxPart, 1.5)
				end
			end
	rushDeb = true
		playRushAnim = true
		keysDown.DoubleW = false
		rushReached = false
	task.delay(settingsModule.RushCooldownDuration, function()
		
		rushDeb = false
		end
	end)


1 Like

you fixed the cool down problem but the the effect replaying over and over by holding w is still there heres a visual example https://gyazo.com/a0d77bfd4e5d67349e0894bdbe80d519

Hmmm, try this.

local function CheckSpecialFlight()
	local wTbl = flightControls.W
	local currentWVel = vel[wTbl.Axis] * wTbl.VelSign
	if (not latching) then
		if keysDown.DoubleW and keysDown.W and rushDeb == false then
		
            rushDeb = true
			RushVfx(char, team, lockedTarget)
			rds.Remotes.Flight:FireServer("rush", lockedTarget)
			task.wait(settingsModule.RushDelay)
			local doubleWTbl = flightControls.DoubleW
			local disfrom = (plr.Character.HumanoidRootPart.Position - lockedTarget.HumanoidRootPart.Position).Magnitude
			if disfrom <= 100 then
			elseif disfrom > 100  then return end
			plr.Character.HumanoidRootPart.CFrame = lockedTarget.HumanoidRootPart.CFrame *  CFrame.new(-6,0,0)
			-- adding same effect after teleporting
			local Rushit_sound = game.ReplicatedStorage.Assets.SFX.RushHit
			Rushit_sound:Play()

			local function RushVfx(vfxChar, vfxTeam, enemyVfxChar)

				local vfxHrp = vfxChar:FindFirstChild("HumanoidRootPart")
				local enemyVfxHrp = enemyVfxChar:FindFirstChild("HumanoidRootPart")
				if vfxHrp and enemyVfxHrp then

					local cf = CFrame.lookAt(vfxHrp.Position, enemyVfxHrp.Position) * CFrame.new(0, 0, -4)
					local rushVfxPart = rds.Assets.VFX.RushVfx_new:Clone()
					rushVfxPart.CFrame = cf
					rushVfxPart.Parent = workspace.Debris
					EmitParticles(rushVfxPart)
					dbs:AddItem(rushVfxPart, 1.5)
				end
			end
	
		playRushAnim = true
		keysDown.DoubleW = false
		rushReached = false
	task.delay(settingsModule.RushCooldownDuration, function()
		
		rushDeb = false
		end
	end)

thank you so much it worked!!!

1 Like