First delete lines 21 to 24. These lines will attempt to spawn a zombie every time spawn is true, regardless of the number of zombies that are present.
2nd up you really need two bools to manage this. You should use one to manage the timer and another to manage the spawn limit.
An even better way would be to manage the whole thing through a single coroutine. The advantage of this is there is no need to check any variables each frame. In fact once you have finished spawning there is no overhead. Here is some pseudo code you can use. Might be a couple of errors as I don’t usually do JavaScript.
#pragma strict
var zombiePrefab : GameObject; // Prefab to spawn
var minWait : int = 1;
var maxWait : int = 10;
var spawnLimit : int;
function Start () {
spawn ();
}
function Spawn() {
var zombiesSpawned : int; //Zombies Spawned
while (zombiesSpawned < spawnLimit){
Instantiate(zombiePrefab, transform.position, transform.rotation);
zombiesSpawned +=1;
yield WaitForSeconds (Random.Range(minWait, maxWait));
}
}