Fix crash in PluginScript destructor
Created by: ktksgit
Cherry picked from https://github.com/godotengine/godot/pull/30187
[EDIT: contains only a subset of above PR]
Created by: ktksgit
Cherry picked from https://github.com/godotengine/godot/pull/30187
[EDIT: contains only a subset of above PR]