fixed a bug where saving a GDScript file crashed the editor
fixed a bug where saving a GDScript file crashed the editor

I changed the loop in #8502, turns out it fixed the error I was facing but introduced a new one. This fixes both

(cherry picked from commit 67886bab1eb0599ec724192a4298c980e6107f2a)

pixelpicosean/my-godot-2.1,pixelpicosean/my-godot-2.1,pixelpicosean/my-godot-2.1,pixelpicosean/my-godot-2.1,pixelpicosean/my-godot-2.1