First: make sure you don’t create an infinite loop creation, always have a way out.
Second: The number of instances or meshes created affect the game’s playback performance, resulting in mild or severe freezes. I recommend doing gradual parts or with coroutines.
Third: Do a test without attributing the materials, as this can reveal whether the poor performance or error is linked to the manipulation of many materials and textures and with this it may be thought that you could use the same shared material in other items that use the same type, to reduce creation processes and items in memory;
Fourth: Whenever you create something, especially multiple ones, always store it somewhere so you can manipulate it. That said, after creating a certain amount of instantiations, it is recommended to destroy the inactive ones or those that are far away, in the case if you play the game with instantiation according to saved data.