I am making a combat for my game, and wanted to have combo like attack system. I decided to use coroutines for this because I can “perform” different attack after everytime it is resumed. But for some reason, unkown for me, when I resume the coroutine after it yields, it starts the coroutine all over again instead of continuing from the yield, I always get only “first” print as in the script below, but never “second” . This is my first time using coroutines and I am overall confused about their usage.
my script:
local function TestAttack()
print("first")
onCooldown = true
hitBox:HitStart()
attackAnim:Play()
plrHumanoid.WalkSpeed = 0
wait(0.6)
hitBox:HitStop()
onCooldown = false
plrHumanoid.WalkSpeed = 12
coroutine.yield()
print("second")
onCooldown = true
hitBox:HitStart()
attackAnim:Play()
plrHumanoid.WalkSpeed = 0
wait(0.6)
hitBox:HitStop()
onCooldown = false
plrHumanoid.WalkSpeed = 12
coroutine.yield()
end
coroutine.create(TestAttack)
local function attack()
if isStunned.Value == false and onCooldown == false then
coroutine.resume(TestAttack())
end
end
sword.Activated:Connect(attack)
btw I have other things defined above this section in the script and I got no errors in output