im struggling a bit with a combat system.
basically, you click to punch, and if you punched less than 1.2 seconds ago, it will play a different animation, reset the timer to 0, going up to a combo of 4, before a short cooldown and reverting back to the first animation(an great example is the strongest battlegrounds). however, if you do not punch within 1.2 seconds of your last punch, the animation will reset back to the first one. does that make sense?
the thing im struggling with is the time since last punch. i’ve tried “while true do” and “for” loops, but they seem to never play the timer again. for example, when the timer starts, it cannot be reset, and won’t work a second time. what is a reliable way of achieving this; am i just doing the loops incorrectly, or is there a better way?
while true do
if attacktime ~= 1.2 then
attacktime += 0.1
task.wait(0.1)
end
end
tick() gives you the seconds passed from 1st january 1970, so create a variable after the first punch, then after another punch try lastPunch - tick() this will give you the difference between the first punch and the other
quick note, if you use tick() wou cant make the attack time 1.4 cause tick would return seconds in integer, so i suggest using courutines and put the function you used in courutine
while true do
if attacktime ~= 1.2 then
attacktime += 0.1
task.wait(0.1)
end
end