How do I make a combo reset after a certain time

Hello there,I was making one of my character’s melee and I was thinking about making combo reset but I don’t know how to make it because I never made it before,if someone can help me then here’s my script:

--VARIABLE--
local hbm=require(game.ReplicatedStorage.MODULE.MuchachoHitbox)
local turn=script.Parent.Gohei.Turn.Value
local TS=game:GetService("TweenService")
--WELDERS
game.ReplicatedStorage.CharacterEvent.Reimu.OnServerEvent:Connect(function(player)
	local Character=player.Character
    Character.CharacterUsing.Value="Reimu"
	local Rhand = Character["Right Arm"]
	player.Character.Animate:Destroy()
	local animate=script.ReimuAnimate:Clone()
	animate.Parent=player.Character
	animate.Disabled=false
	script.Parent.Skills.Visible=true
	animate.Enabled=true
	local Part = Instance.new("Part",Character)
	Part.Name = "GoheiHandle"
	Part.CanCollide = false
	Part.Transparency = 1
	Part.Size = Vector3.new(0.5,0.5,0.5)
	local SFX=script.Parent.Gohei.PlayerSFXFolder:Clone()
	SFX.Parent=player.Character
	local MT6D = Instance.new("Motor6D",Rhand)
	MT6D.Part0 = Rhand
	MT6D.Part1 = Part
	MT6D.C0 = CFrame.new(0,0,0)
script.Parent.Skills.Visible=true
	local Gohei = script.Parent.Gohei.Gohei:Clone()
	Gohei.Parent = Character
    Gohei.Anchored=false
	local Weld = Instance.new("Weld",Part)
	Weld.Part0 = Part
	Weld.Part1 = Gohei
	Weld.C0 = CFrame.new(0,0,0)
end)
--END--
--ATTACKS
--M1
game.ReplicatedStorage.CharacterEvents.ReimuHakurei.Punch.OnServerEvent:Connect(function(player)
	if player.Character:FindFirstChild("UsingSKill") then return end
	if player.Character:FindFirstChild("Stun") then return end
	if player.Character:FindFirstChild("IsBlocking") then return end
	if player.Character.Dashing.Value==true then return end
	if player.Character.CharacterUsing.Value~="Reimu" then return end
	local hum=player.Character:FindFirstChildWhichIsA("Humanoid")
	local hrp=player.Character:FindFirstChild("HumanoidRootPart")
	local animtor=hum:FindFirstChildWhichIsA("Animator")
	local turn=script.Parent.Gohei.Turn.Value
	local hitbox=hbm.CreateHitbox()
	turn+=1
	hitbox.CFrame=hrp
	hitbox.Size=Vector3.new(5,5,5)
	hitbox.Offset=CFrame.new(0,0,-3.5)
	hitbox:Start()
	hitbox.Touched:Connect(function(hit)
		local EnemyHum=hit.Parent:FindFirstChild("Humanoid")
		if hit.Parent.Name~=player.Name then
		if EnemyHum~=nil then
			local hrp=hit.Parent:FindFirstChild("HumanoidRootPart")
			local Block=hit.Parent:FindFirstChild("IsBlocking")
			local Enemy=hit.Parent
			if hrp~=nil then
				if Block==nil then
				EnemyHum:TakeDamage(1)
					local stun = game.ReplicatedStorage.Stun:Clone()
					stun.Parent=hit.Parent
					game.ReplicatedStorage.MakeHitEffect:FireAllClients(Enemy)
					task.wait(0.5)
					stun:Destroy()
				end
			end
			end
		end
	end)
	if turn == 1 then
		local Animation=animtor:LoadAnimation(script.P1)
		Animation:Play()
	end
	if turn == 2 then
		local Animation=animtor:LoadAnimation(script.P2)
		Animation:Play()
		end
		if turn == 3 then
			local Animation=animtor:LoadAnimation(script.P3)
			Animation:Play()
		end
		if turn == 4 then
			local Animation=animtor:LoadAnimation(script.P4)
			Animation:Play()
		end
		if turn == 5 then
			local Animation=animtor:LoadAnimation(script.P1)
			Animation:Play()
		end
		if turn == 6 then
			local Animation=animtor:LoadAnimation(script.P5)
			Animation:Play()
			turn=0
			end
		task.wait(0.3)
		hitbox:Stop()
end)
--M2
1 Like

You can check the Elapsed Time when theEvent happened, you can save the current Time when you add to the combo, and then check if the time is equal to a certain anount.

Also, thats very inefficient code.

1 Like
local function ReturnClick(Duration)
	task.wait(.1)
	
	local HasClicked = false
	local function DetectClick()
		return function ()
			Mouse.Button1Down:Wait()
			HasClicked = true
		end
	end
	task.spawn(DetectClick())
	
	local TimePassed = tick()
	repeat RunService.Heartbeat:Wait() until HasClicked == true or (tick() - TimePassed) > Duration or not Player
	
	if (tick() - TimePassed) > Duration or not Player then
		print("returning false")
		return false
	else
		print("returning true")
		return true
	end
end

This is the function ive devised in my own game, it stores tick which is a number value that shows how much time has passed since Jan 1 1970, then waits until the player either clicks or if subtracting the current tick from the tick i saved is more than a specified amount of seconds (Usually 5 for my game)

After the repeat loop ends by either condition, it checks if the player clicked to bypass the repeat loop by seeing if subtracting the saved tick from the current tick is more than the duration, if so, then the repeat loop terminated because it took so long, and returns false, otherwise, if subtracting the tick from the save tick is not over the max seconds, then its always because the player clicked early enough

This might be a bit confusing but bear with me

2 Likes

It works for me.Thanks for the help!

Ty for respond but that didn’t solve the problem(I’m still learning script)

He basically did what I said to do, but ok.

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