Reset counter after an amount of time?

local module = {}

function module.Function (player)
	local combo = player.PvPStats:FindFirstChild("Combo")
	local combocounter = player.PlayerGui.ComboCounter
	local textlabel = combocounter.Frame.TextLabel
	local hittick = tick()
	
	if combo then
		combo.Value += 1
		combocounter.Enabled = true
		textlabel.Text = combo.Value
		
		print(combo.Value)
	else
		local newcombo = Instance.new("NumberValue")
		newcombo.Name = "Combo"
		newcombo.Parent = player.PvPStats
		
		print(newcombo.Value)
	end
	
	
end

return module

this module is called everytime you damage someone with a tool but how would i reset it if the player has stopped comboing?

1 Like

One way to do it is to use a timer to track when the reset occurs. This timer module or this one should work.

Here’s the logic:

  1. When you first damage someone create the timer and start it.

  2. When you damage them again check to see if the timer has already been created. If so then reset the current time to it’s original state to refresh the combo timer.

  3. Set an event for when the timer ends which resets the combo counter and also destroys the timer.

You could reset the time after detecting the amount of seconds had passed. For example…

Ratelimit check:

local rateData = {}
local resetRate = 1 -- How long the interval would be to reset the rate
local maxRates = 3 -- Max rates within "resetRate" interval (1 second)

function RateCheck(player)
      local currentRData = rateData[player]

      if not currentRData then
         local newRData = {
            Rates = 0;
            LastReset = os.time();
         }

         rateData[player] = newRData
         currentRData = newRData
      end

      local canReset = os.time()-currentRData.LastReset

      if canReset then
         currentRData.LastReset = os.time()
         currentRData.Rates = 0
      end

      local passRate = currentRData.Rates+1 <= maxRates

      currentRData.Rates = currentRData.Rates+1

      if not PassRate then
         return false
      else
         return true
      end
end

for i = 1,5,1 do
    local didPass = RateCheck(game:GetService'Players'.trzistan) -- Checking rate spam from me. Feel free to     change "trzistan" to your username.
    warn(i.." Attempt:", didPass)
    wait(0.01) -- Waiting every hundredth of a second
end

Output of this:

1 Attempt: true
2 Attempt: true
3 Attempt: true
4 Attempt: false
5 Attempt: false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Timer = require(ReplicatedStorage.ModuleScripts.Timer)

local module = {}

function module.Function (player)
	local combo = player.PvPStats:FindFirstChild("Combo")
	local combocounter = player.PlayerGui.ComboCounter
	local textlabel = combocounter.Frame.TextLabel
	local ComboTimer = Timer.new(1.75)
	
	if ComboTimer:GetRemaining() == 1.75 then
		ComboTimer:Start()
		print("combo timer started")
	elseif ComboTimer:GetRemaining() < 1.75 then
		ComboTimer:Stop()
			local ComboTimer = Timer.new(1.75)
			ComboTimer:Start()
		print("combo timer restarted")
	end
	
	ComboTimer:OnStopped(function()
		print("stopped")
	end)
end

return module

i tried to do this but it dont work hmmmm :thinking:

unction module.Function (player)
	local combo = player.PvPStats:FindFirstChild("Combo")
	local combocounter = player.PlayerGui.ComboCounter
	local textlabel = combocounter.Frame.TextLabel
	local hittick = tick()
	
	if combo then
		combo.Value += 1
		combocounter.Enabled = true
		textlabel.Text = combo.Value
		
		print(combo.Value)
	else
		local newcombo = Instance.new("NumberValue")
		newcombo.Name = "Combo"
		newcombo.Parent = player.PvPStats
		
		print(newcombo.Value)
	end
	
	
end

return module

You could use a tick()
local starttick = tick()
if (tick() - starttick) > 5 then return end
starttick=tick()

This post could help you : Tick() How do I use it?

1 Like

how would i mark the 2 different ticks between each hit douh idk how to do that

function module.Function (player,oldtick)
	local combocounter = player.PlayerGui.ComboCounter
	local textlabel = combocounter.Frame.TextLabel
	local combo = tick()-oldtick
	if combo then
		combo.Value += 1
		combocounter.Enabled = true
		textlabel.Text = combo.Value
		
		print(combo.Value)
	else
		local newcombo = Instance.new("NumberValue")
		newcombo.Name = "Combo"
		newcombo.Parent = player.PvPStats
		
		print(newcombo.Value)
	end

in ur other script use
local oldtick = tick()
plr,oldtick
oldtick=tick()

1 Like

Sorry for bumping but I have gotten the time to write it down and test it out after seeing another post on the issue, this should work:

for i,v in pairs(GetTouchingPartsModule.Function(hitbox)) do
			if v.Parent ~= player.Character and v.Name == "HitBox" then
				if not v.Parent:FindFirstChild("ForceField") then
					local player2 = game.Players:FindFirstChild(v.Parent.Name)
					local blocking = BlockingList:FindFirstChild(v.Parent.Name)

					if blocking then
						v.Parent.Humanoid.Health = v.Parent.Humanoid.Health - blockedDamage
						Tag.Function(player)
						if player2 then
							Tag.Function(player2)
							HitBlocked.Function(v.Parent,player2)
						else
							HitBlocked.Function(v.Parent)
						end
					else
						Combo.Add(player)
						ComboTimer:Reset()
						ComboTimer:Start()

						M1Module.Function(v.Parent,player)
						v.Parent.Humanoid.Health = v.Parent.Humanoid.Health - Damage
						Tag.Function(player)

						if player2 then
							Tag.Function(player2)
						end

						ComboTimer.Completed:Connect(function()
							Combo.Stop(player)
						end)
					end
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local combo = {}

function combo.Add (player)
	local combo = player.PvPStats:FindFirstChild("Combo")
	
	if not combo then
		local combo = Instance.new("NumberValue")
		combo.Name = "Combo"
		combo.Parent = player.PvPStats
		
		combo.Value = combo.Value + 1
	else
		combo.Value = combo.Value + 1
	end

end

function combo.Stop (player)
	local combo = player.PvPStats:FindFirstChild("Combo")

	combo.Value = 0
end

return combo

my combo script rn if anyones wondering

1 Like

You should fix this easily.

adding a
local plrs = {}

if tick - plrs[plr] < 10 then
– script here
end

plrs[plr] = tick()