How to make the enemy move back to its waypoint after it's target killed?

Hi guys i have implemented the fps_tutorial AI script and its working for 2 enemy fighting each other. The problem is once the target is dead, the enemy will not go to its waypoint and just stuck there anyone have solution for it? I think is something to do with the array list but due to my limited knowledge i don’t really know how to make one, can somebody help me please?

function Start () {
	// Auto setup player as target through tags
	if (target == null && GameObject.FindWithTag("Player1"))
		target = GameObject.FindWithTag("Player1").transform;
		

	Patrol();
}

function Patrol () {
	var curWayPoint = AutoWayPoint.FindClosest(transform.position);
	while (true) {
		var waypointPosition = curWayPoint.transform.position;
		// Are we close to a waypoint? -> pick the next one!
		if (Vector3.Distance(waypointPosition, transform.position) < pickNextWaypointDistance)
			curWayPoint = PickNextWaypoint (curWayPoint);

		// Attack the player and wait until
		// - player is killed
		// - player is out of sight		
		if (CanSeeTarget ())
			yield StartCoroutine("AttackPlayer");
			
		
		// Move towards our target
		MoveTowards(waypointPosition);
		
		yield;
	}
}


function CanSeeTarget () : boolean {
	if (Vector3.Distance(transform.position, target.position) > attackRange)
		return false;
		
	var hit : RaycastHit;
	if (Physics.Linecast (transform.position, target.position, hit))
		return hit.transform == target;

	return false;
}


function AttackPlayer () {
	var lastVisiblePlayerPosition = target.position;
	while (true) {
		if (CanSeeTarget ()) {
			// Target is dead - stop hunting
			if (target == null)
				Patrol();

			// Target is too far away - give up	
			var distance = Vector3.Distance(transform.position, target.position);
			if (distance > shootRange * 3)
				return;
			
			lastVisiblePlayerPosition = target.position;
			if (distance > dontComeCloserRange)
				MoveTowards (lastVisiblePlayerPosition);
			else
				RotateTowards(lastVisiblePlayerPosition);

			var forward = transform.TransformDirection(Vector3.forward);
			var targetDirection = lastVisiblePlayerPosition - transform.position;
			targetDirection.y = 0;

			var angle = Vector3.Angle(targetDirection, forward);

			// Start shooting if close and play is in sight
			if (distance < shootRange && angle < shootAngle)
				yield StartCoroutine("Shoot");
		} else {
			yield StartCoroutine("SearchPlayer", lastVisiblePlayerPosition);
			// Player not visible anymore - stop attacking
			if (!CanSeeTarget ())
				return;
		}

		yield;
	}
}

I don’t know whether this will solve your problem, but I would just return when the enemy is dead:

     // Target is dead - stop hunting
     if (target == null)
         return; // just return to resume the Patrol coroutine

i got my enemies going back to waypoints but i using navmesh to SetDestination( route[currentPoint].position); but for yours looks like you should just take patrol function out of start and set it to run in update is target is null