I was going to make combat system whenever player clicks. It plays different animations. What I want to do is when player stop clicking for a while. The animation resets to the beginning.
I have the issue on using thread or something whatever. Here’s an example:
-- This is just the only issue I'm talking about. If you need to see more code please tell me.
local runservice = game:GetService("RunService")
local returncombo
local hit_debounce = false
local hit = false
runservice.Heartbeat:Connect(function (deltaTime)
if COMBO == 0 then full_combo = false already_hit = false end
if COMBO == 1 or COMBO == 2 or COMBO == 3 then full_combo = false already_hit = true COMBO_DURATION = math.abs(LIGHTCOMBO_COOLDOWN - HIT_COOLDOWN) end
if COMBO == 4 then COMBO_DURATION = math.abs(LIGHTCOMBO_LAST_COOLDOWN - HIT_COOLDOWN) full_combo = true SetReturnComboStartCooldown() task.wait(1) COMBO = 0 end
if not hit_debounce and hit then
hit_debounce = true
task.cancel(returncombo) -- issues here
returncombo = task.spawn(returnCombo) -- issues here
end
end)
The thing is I know only few on how to use coroutine and task. I want an example that can make me understand.