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
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
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)