Detect when player hasnt been punching for a certain amount of time

what im trying to do is this:
when player hasn’t been punching for say, like 2.5 seconds, then it resets their combo back to 1

what ive tried doesnt really work, as it checks as the person is in their combo and resets it mid punching

This is my script:

local OnCoolDown = false
local CoolDownTime = 0.3
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local TargetFound = false
local rs = game:GetService("ReplicatedStorage")
local hbEvent = rs.Events.hitbox2
local combo = 1
local h = plr.Character.Humanoid
local swing = script:WaitForChild("swing")
swing.Parent = plr.Character.HumanoidRootPart
local Punching = false
local uis = game:GetService("UserInputService")



if h:GetState() == Enum.HumanoidStateType.Jumping then
	print("Jump")
end

Mouse.Button1Down:Connect(function()
	local Can = game.ReplicatedStorage.AbleHit.Value
	if OnCoolDown == false and not plr.Character:FindFirstChildWhichIsA("Tool") then
		Punching = true
		h.JumpHeight = 0
		h.JumpPower = 0
		print(Can)
		if combo == 1 then
			print("1")
			OnCoolDown = true
		combo = 2
		local track = h:LoadAnimation(script.Combo1)
		track:Play()
		swing:Play()
			hbEvent:FireServer()
		wait(CoolDownTime)
			h.JumpHeight = 7.5 
			h.JumpPower = 50
		Punching = false
		OnCoolDown = false
		return
		
		
		end
		
		if combo == 2 and not plr.Character:FindFirstChildWhichIsA("Tool") then
			print("2")
			Punching = true
			OnCoolDown = true
			h.JumpHeight = 0
			h.JumpPower = 0
			combo = 3
			local track = h:LoadAnimation(script.Combo2)
			track:Play()
			swing:Play()
			hbEvent:FireServer()
			wait(CoolDownTime)
			Punching = false
			h.JumpHeight = 7.5
			h.JumpPower = 50
			OnCoolDown = false
			return


		end
		
		if combo == 3 and not plr.Character:FindFirstChildWhichIsA("Tool") then
			print("3")
			Punching = true
			OnCoolDown = true
			h.JumpHeight = 0
			h.JumpPower = 0
			combo = 4
			local track = h:LoadAnimation(script.Combo3)
			track:Play()
			swing:Play()
			hbEvent:FireServer()
			wait(CoolDownTime)
			Punching = false
			h.JumpHeight = 7.5
			h.JumpPower = 50
			OnCoolDown = false
			return


		end
		
		if combo == 4 and not plr.Character:FindFirstChildWhichIsA("Tool") and h:GetState() == Enum.HumanoidStateType.Freefall then
			print("downslam")
			OnCoolDown = true
			h.JumpHeight = 0
			h.JumpPower = 0


			combo = 1
			local track = h:LoadAnimation(script.Downslam)
			track:Play()
			swing:Play()
			hbEvent.Parent.hitbox2Down:FireServer()
			plr.Character.sprint.Enabled = false
			wait(.01)
			plr.Character.plrStun.Value = true
			wait(.8)
			h.JumpHeight = 7.5
			h.JumpPower = 50
			plr.Character.plrStun.Value = false
			plr.Character.sprint.Enabled = true

			OnCoolDown = false
			return


		end
	
		
		if combo == 4 and not plr.Character:FindFirstChildWhichIsA("Tool") then
			
			local Heldspace = uis:IsKeyDown(Enum.KeyCode.E)
			Punching = true
			h.JumpHeight = 0
			h.JumpPower = 0
			if Heldspace == true then
				combo = 1
				local track = h:LoadAnimation(script.Uptilt)
				track:Play()
				swing:Play()
				rs.Events.hitbox2Up:FireServer()
				plr.Character.sprint.Enabled = false
				wait(.01)
				plr.Character.plrStun.Value = true
				wait(1)
				Punching = false
				h.JumpHeight = 7.5
				h.JumpPower = 50
				plr.Character.plrStun.Value = false
				plr.Character.sprint.Enabled = true

				OnCoolDown = false
				return
			end
			print("4")
			Punching = true
			OnCoolDown = true
			
			
			combo = 1
			local track = h:LoadAnimation(script.Combo4)
			track:Play()
			swing:Play()
			hbEvent.hitbox2Last:FireServer()
			plr.Character.sprint.Enabled = false
			wait(.01)
			plr.Character.plrStun.Value = true
			wait(1.5)
			Punching = false
			h.JumpHeight = 7.5
			h.JumpPower = 50
			plr.Character.plrStun.Value = false
			plr.Character.sprint.Enabled = true
	
			OnCoolDown = false
			return


		end
		
		
		
		
		
	end
end)


Use tick in this situation.

Update the tick every time the player punches.

local start = tick() --tick

task.wait(1) -- wait 1 second
start = tick() -- set the start tick to 0 (use this when the player punches)
task.wait(2) -- wait two seconds

local final = tick()-start --how much time has passed since last tick update
print(final) --print final

thanks man that worked!
wish you luck on all of your projects!

never used tick() before so i was kinda guessing based off the info you gave me, but figured it out! once again, thanks man!

No problem bro, and thanks for the luck!

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