This sounds like a crash in the game - a random crash that only happens in debug mode. It is no direct crash in the script, otherwise you'd see an error message, but something else, like a subsequent crash due to a script problem, or a damaged file.
I would remove parts of the project until it does not crash anymore, then move them back step by step. This is the best method for finding random crashes.