Sometimes when I've been writing scripts with ChatGPT I've asked it to do a little too much where it either stops sending in code, or the code gets put into code and non-code boxes. At times ChatGPT will stop giving me the code all together, and I'll get into a continuous loop where I keep asking it to finish, it starts over, I ask it again, and then I finally say stop.
So what I've been trying to do instead is ask it to do things differently, where instead of putting all the code in one HTML file, if I'm building a front-end, I'll ask it to put it into different files, like one for HTML and one for Javascript.
That way it helps it write code a little more modular, and where it doesn't break up or stop generating code. This will still depend on what you are having it write, but altogether, it does help.
At the same time instead of asking it to create whole new scripts, use it to update pieces of scripts, specific functions, or ask it more general questions like how you would do it in theory vs code.