Space Shooter Tutorial - Player Respaner: IEnumerator not executing all code ,

I have completed the Space Shooter tutortioal and currently wanting to impliment a lives system.
I’m open to other ways of doing this but so far to avoid re doing the current meachanics I am using IEnumeratore to set the player to active and false. I am using it in the DestroyByContact script.

My goal is to:

  1. Set Player active to false
  2. wait 3 seconds
  3. Set player active to true but with no collider (shot term invincibility)
  4. wait 3 seconds
  5. Set Player collider to true

For some reason the IEnumeratore just does not work and won’t trigger the code after the second wait.
If I just have log out put I can get through the two wait times without issue but as soon as I bring in the setactive and collider true/false it breaks.
There are no errores in the console.

IEnumerator Function:

    IEnumerator RespawnPlayer()
    {
        Debug.Log("Dead");
        player.SetActive(false);


        yield return new WaitForSeconds(2);
        Debug.Log("respawn");
        player.SetActive(true);
        playerCollider.enabled = false;

        yield return new WaitForSeconds(2);
        Debug.Log("Collider On");
        playerCollider.enabled = true;

    }

Full Script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DestroyByContact : MonoBehaviour
{
    
    public GameObject explosion;
    public GameObject playerExplosion;
    public int scoreValue;
    
    private GameController gameController;

    private bool gameOver;
    private GameObject player;
    private Collider playerCollider;


    void Start()
    {
        
        GameObject gameControllerObject = GameObject.FindWithTag("GameController");
        if(gameControllerObject != null)
        {
            gameController = gameControllerObject.GetComponent<GameController>();
        }
        if(gameController == null)
        {
            Debug.Log("Cannot find 'Gamecontroller' script");
        }
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Boundary") || other.CompareTag("Enemy"))
        {
            return;
        }

        if (explosion != null)
        { 
        Instantiate(explosion, transform.position, transform.rotation);
        }   

        if(other.CompareTag("Player"))
        {
            Instantiate(playerExplosion, other.transform.position, other.transform.rotation);

            gameOver = gameController.GameOver();

            if(gameOver == false)
            {
                player = GameObject.FindGameObjectWithTag("Player");
                playerCollider = player.GetComponent<Collider>();

                
                StartCoroutine(RespawnPlayer());
              
                return;
            }
        }
        else // the else stops points being scored from cashing into an enemy/hazzard  
        {
            gameController.AddScore(scoreValue);
            
        }

        Destroy(other.gameObject);
        Destroy(gameObject); 
    }


 
    IEnumerator RespawnPlayer()
    {
        Debug.Log("Dead");
        player.SetActive(false);


        yield return new WaitForSeconds(2);
        Debug.Log("respawn");
        player.SetActive(true);
        playerCollider.enabled = false;

        yield return new WaitForSeconds(2);
        Debug.Log("Collider On");
        playerCollider.enabled = true;

    }

}

GameOver function from the GameController Script:

public bool GameOver()
    {
        if(lives > 0)
        {
            lives = lives - 1;
            livesText.text = "X " + lives;
            gameOver = false;
            return false;
        }
        gameOverText.text ="Game Over";
        totalScoreText.text = "Top Score: " + score;

        gameOver = true;
        return true;
    }

Am I using the I enumerator in the wrong way?

Thanks

Coroutines are handled by the component they have been started on. They are not stored in some sort of global coroutine register or anything.

Thus, this combination:

StartCoroutine(RespawnPlayer());
// ...
Destroy(gameObject);

means that you start a coroutine, but destroy it alongside the object you started it on before the next frame. As a result, the coroutine will execute anything until the first yield statement, but will be destroyed before it can continue after that.