As you can see I've fixed some duplicated code by making safeSpawn a method of Server, but more importantly I've put in a simple 10-loop limit that will prevent an infinite loop if a cell fails to spawn safely.
Feel free to close if you're already working on a better solution.
Still not the best solution. using loops slows down performance. you'd be better off using async functions and just letting you wait instead of checking. I'm sure there is a better way to fix this.
As you can see I've fixed some duplicated code by making safeSpawn a method of Server, but more importantly I've put in a simple 10-loop limit that will prevent an infinite loop if a cell fails to spawn safely.
Feel free to close if you're already working on a better solution.