Infinite letter loop in Unity dialogue

Hello! I am trying to make a dialogue system in Unity by following this tutorial: (29) 5 Minute DIALOGUE SYSTEM in UNITY Tutorial - YouTube. There is a slight twist to this and that is that I am triggering this conversation based on an event which is whether the boss is in sight or not.

However, once the conversation starts, it just prints out the letter c endlessly and goes into an infinite loop. I’ve tried looking for the problem but I can’t seem to figure it out. Any help is much appreciated. Here is the code for the Event/Delegate class and the Dialogue class respectively:

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

public class DialogueDelegateEvent : MonoBehaviour
{
    public delegate void BossInSight(bool inSight);

    public static event BossInSight OnBossInSight;

    //for ending the conversation:
    public delegate void ConversationComplete();
    public static event ConversationComplete OnConversationComplete;

    private static DialogueDelegateEvent instance;

    public static DialogueDelegateEvent Instance
    {
        get
        {
            if (instance == null)
            {
                instance = FindObjectOfType<DialogueDelegateEvent>();
            }
            return instance;
        }
    }

    public void SetBossInSight()
    {
        OnBossInSight?.Invoke(true);
    }

    public void EndConversation()
    {
        OnConversationComplete?.Invoke();
    }
}

Dialogue.cs class:

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

public class Dialogue : MonoBehaviour
{
    public TextMeshProUGUI textComponent;
    public string[] lines;
    public float textSpeed;

    private int index;

    private void OnEnable()
    {
        DialogueDelegateEvent.OnBossInSight += BeginConversation;
        BeginConversation(false);
    }

    private void OnDisable()
    {
        DialogueDelegateEvent.OnBossInSight -= BeginConversation;
    }

    void Start()
    {
        textComponent.text = string.Empty;
    }

    private void BeginConversation(bool inSight)
    {
        if (inSight)
        {
            Time.timeScale = 0f;
            StartDialogue();
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if(textComponent.text == lines[index])
            {
                NextLine();
            }
            else
            {
                textComponent.text = lines[index];
                StopAllCoroutines();
            }
        }
    }

    void StartDialogue()
    {
        index = 0;
        StartCoroutine(TypeLine());
    }

    IEnumerator TypeLine()
    {
        foreach (char c in lines[index].ToCharArray())
        {
            textComponent.text += c;
            yield return new WaitForSeconds(textSpeed);
        }
    }

    void NextLine()
    {
        if (index < lines.Length - 1)
        {
            index++;
            textComponent.text = string.Empty;
            StartCoroutine(TypeLine());
        }
        else
        {
            DialogueDelegateEvent.Instance.EndConversation();
            gameObject.SetActive(false);
            Time.timeScale = 1f;
        }
    }
}

As a general check, are you only invoking the boss in sight event once, or is it possible that it’s calling it many times?

I think the issue here is the combination of these two lines - first setting timeScale to 0:
Time.timeScale = 0f;
and second:
yield return new WaitForSeconds(textSpeed);

While Time.timeScale is set to 0, WaitForSeconds will not do anything. You could use WaitForSecondsRealtime here instead - see the manual page for it here for more information: Unity - Scripting API: WaitForSecondsRealtime