I don't know how to fix that scripting issue unfortunately, but I'm sure I know the solution to this. :D What I usually do is think on what Pokemon would make sense in your region, or area. I think of it like putting animals into the real world where they should live. For example, let's say my region is one that is close to the ocean, I would have Pokemon like Lotad, as an example, as they could live as lily pads would in a river.
Another example could be, your area is mountainous, you could put Pokemon you think can withstand cold climates, rocky terrain, and can resist air pressure, so Pokemon like, Geodude, or Castform would make sense.
Alternatively, you can also check how they're classified in the Fire Red/Leaf Green Pokedex, since that Pokedex displays where Pokemon would usually live. e.g. It says that Bulbasaurs live in Forests, and Charmanders in Mountains.
Hope this is helpful. :)