Spawn enemy until number is reached js

So, I recently Had an idea. Instead of spawning an object then waiting a given amount of time to spawn another, why not just check how many have spawned. For example If I want ten Gizmos to spawn, it would spawn 10 and wait until they were gone. then spawn ten more. The code I am using now works for a timed delay but the spawn in constant/infinite. Feel free to add onto the code I have or point me in the right direction. Thanks for your time!

here is the code (ps. I am a beginner):

var SpawnObject : GameObject; 
   
   // in seconds 
   var SpawnStartDelay : float = 0; 
   var SpawnRate: float = 5.0; 
   
   function Start() 
   {
       InvokeRepeating("Spawn", SpawnStartDelay, SpawnRate); 
   } 
   
   // Spawn the SpawnObject 
   function Spawn() 
   {
       Instantiate(SpawnObject, transform.position, transform.rotation); 
   }

Just use CancelInvoke when you hit your limit.