So I am making a combat system and I want to have a timer that will start from 0 every time a player will punch, there are 4 punches/animations and I want to know if it has been more than 1.3 seconds since I clicked so I can reset the animation to start from the first one.
you can use os.time() or os.clock() and get the elasped time (currentTime - timestamp)
local lastFire = os.clock(); -- keep track of the current time here
task.wait(2) -- wait a bit
local elaspedTime = os.clock() - lastFire -- elasped time since we first got the data
if elaspedTime > 1.3 then -- time check (if the time has goe over 1.3 seconds)
-- do something
end
It is working but there is a problem, If I click more than one time there will be 2 or more timers, some of them from the past that will reset my punch system, so how would I implement this to always have just one timer?
Here is the code:
coroutine.resume(coroutine.create(function()
task.wait(2)
local elapsedTime1 = os.clock() - timer
if elapsedTime1 >= 1.3 then
count = 1
char:SetAttribute("Combo", 1)
end
end))
local corountine = false
coroutine.resume(coroutine.create(function()
if not corountine then
corountine = true
task.wait(2)
local elapsedTime1 = os.clock() - timer
if elapsedTime1 >= 1.3 then
count = 1
char:SetAttribute("Combo", 1)
end
corountine = false
end
end))
The code doesn’t give me any errors but nothing happens, I even placed a print statement to see if it is working, I’ll try to see from what this thing might come from. If you have any ideas please tell me. Thank you for your time
To be more precise, if I click 3 times, and then I stop, my combo will reset 3 times because there are 3 timers, but I want to reset just once when I stop