Somethings Wrong After Restarting Scene

Hi,

I am making a Tower Defense Game and after pressing Restart Button, sometimes restarting well, sometimes not restarting properly i need help.

This is my restart code:

    public void Toggle()
    {
        ui.SetActive(!ui.activeSelf);
        topUI.SetActive(!topUI.activeSelf);
        if (ui.activeSelf)
        {

            Time.timeScale = 0f;
        }
        else
        {
            Time.timeScale = 1f;
        }
    }
    public void retry()
    {
        scenefader.FadeTo((SceneManager.GetActiveScene().name));
        Toggle();
    }

and i believe this is corrupt script:

public float timeBetweenWaves = 5f;
public float countdown = 5f;

private int waveIndex = 0;
public Text waveCountDownText;
void Update()
{
    if(EnemiesAlive > 0)
    {
        return; 
    }
    if (countdown <= 0f && EnemiesAlive<=0)
    {
        StartCoroutine(SpawnWave());
        countdown = timeBetweenWaves;
        return;
    }
    countdown -= Time.deltaTime;
    countdown = Mathf.Clamp(countdown, 0f, Mathf.Infinity);
    waveCountDownText.text =Mathf.Round(countdown).ToString();
    waveCountDownText.text = string.Format(" {0:00.00}", countdown);
}

   IEnumerator SpawnWave()
    {
    PlayerStats.Rounds++;
    WaveInfo wave = waves[waveIndex];
        for (int i = 0; i < wave.count; i++)
        {
            SpawnEnemy(wave.enemy);
            yield return new WaitForSeconds(1f / wave.rate);
        }
            waveIndex++;
        if (waveIndex == waves.Length)
        {
        Debug.Log("level won");
        this.enabled = false;
        }

}

[117006-adsızzzzzzzzzzzzzzzzzz.png|117006]

You can see on top middle of screen time countdowning and when it’s equal to 0 wave starting
but sometimes after restarting the scene i don’t know why time is not starting to count down and not showing it on text too. You can see on Second Picture time is not showing and wave is won’t starting.

[117007-adsızz2222222222222222222zz.png|117007]

i fixed by debugging
i changed my code to this :

     void Start()
    {
        countdown = 5f;
        waveCountDownText.text = Mathf.Round(countdown).ToString();
        EnemiesAlive = 0;
    }
    void Update()
    {
        if (EnemiesAlive > 0)
        {
            return;
        }
        else
        {
            if (countdown <= 0f)
            {
                StartCoroutine(SpawnWave());
                countdown = timeBetweenWaves;
                return;
            }
            else
            {
                countdown -= Time.deltaTime;
                countdown = Mathf.Clamp(countdown, 0f, Mathf.Infinity);
                waveCountDownText.text = Mathf.Round(countdown).ToString();
                //waveCountDownText.text = string.Format(" {0:00.00}", countdown);
            }
        }
    }
       IEnumerator SpawnWave()
        {
        PlayerStats.Rounds++;
        WaveInfo wave = waves[waveIndex];
            for (int i = 0; i < wave.count; i++)
            {
                SpawnEnemy(wave.enemy);
                yield return new WaitForSeconds(1f / wave.rate);
            }
                waveIndex++;
            if (waveIndex == waves.Length)
            {
            Debug.Log("level won");
            this.enabled = false;
            }
        }