Stop/pause Traffic Light routine and restart from beggining?

Hello everyone!
I have a traffic light, were is start its routine after the countdown finishes, I have held the process by a boolean, and I am calling it in an Update function, simply control the process by the boolean “playTrafficLights”, please check the code, its simlpe and clear.

Now my problem is when I need to trigger the lights (Start the loop/routine/process from beginning, no matter where is the previous one)
To explain more, I have a trigger(collider) close to the traffic lights, I will turn the red light on whenever the car gets close by, so OnTriggerEnter(from another script) , I am calling the function “TriggerTrafficLights()” ,which in turn changes the bool value.

First I taught , a second call to a function will stop the process/flow of the first call…
But as I tested , I have a mess in the colors since two parallel calls are having conflicts and even the order is in a mess.

can someone give me a hint of a technique of how to break the process of the lights(wherever it has reached execcution) and start a new one!

I am reading about coroutines, but still couldn’t find a solution!
Many thanks!

function Start() {
   
   StartCountDown();
}

function Update() {      	
  if(playTrafficLights)	
	TrafficLight();
}

function TrafficLight() {
   playTrafficLights = false;             
   // red is on	
   yield WaitForSeconds (8);
   // green is on
   yield WaitForSeconds (8);
   // yellow is on
   yield WaitForSeconds (8);
   playTrafficLights = true;	
 }

 function TriggerTrafficLights() {
     playTrafficLights = true;
 }

 function StartCountDown(){
     // Do staff
     // show countdown // do other staff 

     playTrafficLights = true;
 }

When I have something like this that requires I break and reset execution, I usually just do my own timing and don’t use coroutines. My usual language is C#, but below is a bit of Javascript to show what I mean. SetLight will set the light to any state and restart the timer.

var lightTime : float = 8.0;
private var timeStamp : float;
var isRunning = true;

enum LightState { Red, Yellow, Green };

private var state : LightState = LightState.Red;

function Start () {
	SetLight(LightState.Red);
	timeStamp = Time.time + lightTime;
}

function Update () {
	if (!isRunning) return;
	if (Time.time > timeStamp) {
		timeStamp = Time.time + lightTime;
		if (state == LightState.Green)
			state = LightState.Red;
		else
			state = state + 1;	
		ChangeLight();
	}
}

function ChangeLight() {
	if (state == LightState.Red) {
		Debug.Log("Set the light to red");
	}
	else if (state == LightState.Yellow) {
		Debug.Log("Set the light to Yellow"); 
	}
	else {
		Debug.Log("Set the light to Green");
	}
}

function SetLight(newState : LightState) {
	state = newState;
	timeStamp = Time.time + lightTime;
}