Something wrong with this part of my script

I’m making a function that saves a model for datastore2 but when I save my values, the output goes crazy and I get like 15k datastore2 messages in there.

21:55:09.513 - ServerScriptService.DataStore2.TableUtil:6: stack overflow

21:55:09.526 - Stack Begin

21:55:09.527 - Script ‘ServerScriptService.DataStore2.TableUtil’, Line 6 - function clone

21:55:21.312 - Script ‘ServerScriptService.DataStore2.TableUtil’, Line 8 - function clone (x16377)

21:55:21.312 - Script ‘ServerScriptService.DataStore2’, Line 46 - function clone

21:55:21.312 - Script ‘ServerScriptService.DataStore2’, Line 181 - function Set

21:55:21.313 - Script ‘ServerScriptService.DataStore2’, Line 389 - function Set

21:55:21.313 - Script ‘ServerScriptService.save_script’, Line 300 - function save_to_model

21:55:21.313 - Script ‘ServerScriptService.save_script’, Line 307

Here is part of my function code (not all of it because i don’t want to share too many scripts.)

			    terrainxposition,
				terrainyposition,
				terrainzposition,
				terrainxrotation,
				terrainyrotation,
				terrainzrotation,
				terrainxsize,
				terrainysize,
			    terrainzsize,
			    terrainmaterials,
			    objectxposition,
			    objectyposition,
			    objectzposition,
			    objectxrotation,
			    objectyrotation,
			    objectzrotation = {},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}

-- later in the code...

			terrainxpositionStore:Set(terrainxposition)
			terrainypositionStore:Set(terrainyposition)
			terrainzpositionStore:Set(terrainzposition)
			
			terrainxrotationStore:Set(terrainxrotation)
			terrainyrotationStore:Set(terrainyrotation)
			terrainzrotationStore:Set(terrainzrotation)
			
	
			terrainxsizeStore:Set(terrainxsize)
			terrainysizeStore:Set(terrainysize)
			terrainzsizeStore:Set(terrainzsize)
			terrainmaterialsStore:Set(terrainmaterials)
			objectxpositionStore:Set(objectxposition)
			objectypositionStore:Set(objectyposition)
			objectzpositionStore:Set(objectzpositionStore)
			objectxrotationStore:Set(objectxrotation)
			objectyrotationStore:Set(objectyrotation)
			objectzrotationStore:Set(objectzrotation) 

I checked that the :Set function calls weren’t in a for loop and it wasn’t so I tried replacing the function calls with a print statement and it only printed once which makes me believe there is something wrong with my :Set functions.

It’s a stack overflow, meaning a function is calling itself over and over again.

Check to see if your code has functions calling themselves. If your function(s) are, remove the line that calls itself.

Also your current method of saving the model is very inefficient the only things which you should be saving are the name of the model and the Cframe in relation to the what is the model is being placed on.

I’m determined that it is the :Set functions doing, not the function that they are in as when i use print the print only happens once, but I cant see what is wrong with them. Maybe my datastore2 module is broken and the issues you were talking about are in there actually so i might re add the module when i get time.

OK the module is fine so I’ll keep debugging. I could dm the entire script maybe.