Issue invloving coroutines and animations

I am currently making an combo system in which the player is locked in place while the animation is playing . It’s using a coroutine that locks the player while the animation is playing.
Here 's my combo code:

        if (Input.GetKeyDown("joystick button 1") )
        {
            if ((LastAttack - Time.time) > 0.5f || AttackCounter == 0)
            {
                anim.SetTrigger("Attack1");
                // length of the animation 'attack 1'
                float timeOfAnimation = GetComponent<Animator>().runtimeAnimatorController.animationClips[7].length;
                StartCoroutine(STOP(timeOfAnimation, 0.3f));
                AttackCounter = 1;
            }
            else if (AttackCounter == 1)
            {  
                anim.SetTrigger("Attack2");
                // length of the animation 'attack2'
                float timeOfAnimation = GetComponent<Animator>().runtimeAnimatorController.animationClips[8].length;
                StartCoroutine(STOP(timeOfAnimation,0f));
                AttackCounter = 0;
            }
            LastAttack = Time.time;
        }

Now here’s my coroutine “STOP”:

    public IEnumerator STOP(float duration,float offset)
    {
        FreezePlayer();
        FreezeRotation();
            yield return new WaitForSeconds((duration-offset));
            unFreezePlayer();
            unFreezeRotation();
    }

The player is locked in place during the first attack and first half of the second attack.
Changing the values of the duration and the offset when calling the coroutine “STOP” for the second attack has no effect.

It’s the first time i’m using coroutines

Any thoughts ?

Can you describe what behavior you want? Trying to follow in pseudocode:

// Player presses button 1
// If its been more than 0.5s since last attack or attackcounter is 0:
  // Start Attack1 anim
  // Freeze player after 0.3s?
  // set attack counter to 1
// else if attack counter is 1:
  // start Attack2 anim
  // Freeze player immediately?
  // reset attack counter to 0

I think what might be happening is you are starting the STOP coroutine with the first attack, and then before it has finished you are starting another STOP coroutine from your second attack. So they are conflicting.

Thank you for your answer . I’ve got the issue figured out, my two coroutines were indeed conflicting so i simply stopped the first with “StopAllCoroutines()” before starting the second.