This, always. While you can write entire scripts in the dialog for your event, you should not. For best maintainability, and for other uses, event scripts should be one-liners that just pass all the relevant event information to a project library script.
I have the script put in project library and Scheduled event to call it. If I want a button to call it would the best way be to screen button --> changes tag [RunXScriptTag] then have gateway tag change script monitor [RunXScriptTag] to call the function instead of having the screen button calling the function directly?
I tried that at first but it locked up the client. Script is quite large, checking a DB table against tag values and correcting if needed. Takes about 2 min to run if no changes and can be much longer if it finds and corrects errors. I don't need more then 1 client to run it at any time. This is an administration level operation so the "button" would be restricted access and rarely used.