Since you are spawning them with a delay and checking array length after each kill, it could be that it removes from the array leaving it = 0 and it moves to next wave while still spawning the remaining from prev wave?
Since you are spawning them with a delay and checking array length after each kill, it could be that it removes from the array leaving it = 0 and it moves to next wave while still spawning the remaining from prev wave?