Random Crashing with Courotine

void Start()
StartCoroutine(randomRoars());
}

    IEnumerator randomRoars()
    {
        while (true)
        {
 
            if (!monsterSound1.isPlaying)
            {
                float rdmtime = Random.Range(0, 10);
                yield return new WaitForSeconds(rdmtime);
                monsterSound1.clip = roars[Random.Range(0, roars.Length)];
                monsterSound1.Play();
            }
        }

        }

This snippet of code is causing my editor to crash every time. Theres moe to it but this is all the code that is causing it, i tested it for a hour and a half removing little snippets. Anyways, any idea why this would be?

Cortouines are a form of cooperative multitasking. You must yield occasionally or other code never has a chance to run.

In your code, if monsterSound1.isPlaying is true your loop effectively becomes this:

while (true)
{
}

That’s an infinite loop. Since there is no yield being executed, no other code will ever be allowed to execute. You need to have a yield if monsterSound1.isPaying is true, something like…

while (true)
{
    if (!mosnterSound1.isPlaying)
    {
         // play sound
    }
    else
    {
         yield return null;  // yield until the next frame, 
         // or you could yield  for a certain amount of time or whatever,
         // but you must yield
    }
}