Exported game crashes when going back to main scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Entity2020 studios

I’ve exported my Godot game, but if I try to go back to the main menu while playing, it crashes. This doesn’t happen in the editor, it only happens in the exported version. And it doesn’t show any errors in the editor when it happens.
I use the following script to return to the main menu:

func _on_Quit_pressed():
Global.Loading = 1

Is this just a glitch with Godot 4? Or is there an actual problem?

Also, the Global.Loading variable is used for determining what level to take the player to when they’re on the loading screen, and it’s found in the script of the menu screen. I feel like autoloading the script for the menu screen isn’t helping.

Entity2020 studios | 2023-05-15 15:38

change_scene_to_file() returns an Error result. You should be capturing that result and checking it for success / failure. If you get a non-OK result, you should detect and handle it appropriately.

jgodfrey | 2023-05-15 20:54

how do I check for success or failure?

Entity2020 studios | 2023-05-17 15:34

Something like this:

var result = get_tree().change_scene_to_file("res://InterfaceScreens/MenuScreen.tscn")
if result != OK:
    print("Scene load failure!")
    print("Scene load was success")

jgodfrey | 2023-05-17 17:19