Reset Hit counter

I have a NumberValue called Hits_Value inside of my character and that value increases by one every punch, so I wanna reset it every 2 seconds if the value is not changing I mean player is not attacking anymore.

Here’s not working script:

hitsreset = {}
--yeah it is in game.PlayerAdded there just some more stuff not needed
local _hits = Instance.new("NumberValue",Character)
		_hits.Value = 0
		_hits.Name = "Hits_Value"

		_hits:GetPropertyChangedSignal("Value"):Connect(function()	
				hitsreset[Character.Name] = false
				wait(3)
				hitsreset[Character.Name] = true	
			
		end)
		
		_hits.Changed:Connect(function()
			if hitsreset[Character.Name] == true then
				_hits.Value = 0
				hitsreset[Character.Name] = false
				
			end
1 Like

have another value or something that stores the last time the player attacked (tick())
and then have another thread that checks if tick() - LastAttackTick > 2 then reset

how can i implement that
30 c
h

something like this?

	_hits:GetPropertyChangedSignal("Value"):Connect(function(value)	
			hitsreset[Character.Name] = false
			lasthit[Character.Name] = tick()
			
			if tick - lasthit[Character.Name] > 2 then
			
			hitsreset[Character.Name] = true	
			_hits.Value = 0
			end
		end)
1 Like
local LastPunchTick = nil
function Punch()
	LastPunchTick = tick()
	DoEverythingElse...
end


spawn(function()
	while true do
		wait(2)
		if LastPunchTick ~= nil then
			if tick() - LastPunchTick > 2 then
				_hits.Value = 0
			end
		end
	end
end)
2 Likes

the thing is i dont wanna do it in one script with punch so yeah

with the script i wrote it says
image

1 Like

Why do I need number value?
30

1 Like

To share the tick between two scripts?

1 Like

uh as you can see in post i already created number value :confused:

here what i wrote its not working, it doesnt reset my value

_hits:GetPropertyChangedSignal("Value"):Connect(function(value)	
			hitsreset[Character.Name] = false
			lasthit[Character.Name] = tick()
			
			if tick() - lasthit[Character.Name] > 2 then
			
			hitsreset[Character.Name] = true	
			_hits.Value = 0
			end
		end)
1 Like

you change the tick then instantly check if two seconds have passed, explain how that makes sense to you

2 Likes

Oh… Yeah, thank you it worked

1 Like