ScriptEditorService: Attempt to use a closed document

Hi, I’m struggling to figure out what causes this error:


As it shows up, those lines below are erroring but this is not what I actually asked for. Once upon calling GetScript on the document:



The error appears on the output in only one of my places, yet I want to guarantee that the plugin works in every place. I’ve tried other places like this local place but it seems to happen only in that place! Do you know how to solve it?