Looping section of stacktrace
I found that certain combinations of gsub, game.print, pcall, xpcall, and function calls can result in a crash from stack overflow. However, some combinations do not cause any crashes.When there is a crash it will be because there was an error in the loaded string, which is normally caught by pcall or xpcall.
When the loaded string has no errors then everything works as expected, for all cases.
Below you can find the minimum required code in order to reproduce the crash and all the cases that I found.
I dont know if the custom environment or the load function is the cause of the error which is why I have left both in my example.
The final case with pcall, raw_command_error and gsub will always work and shows the correct result for each test.
Minimum Scenario Code
Tests and Results