Variable doesn't store reference to a scene

Ok, I’m about to kill someone. This is what’s happening:

I create a variable to store a reference to my GUI scene (conveniently named GUI), I proceed to loop through all the scenes looking for said GUI (printing every scene’s name) and then I attempt to store a reference to the GUI scene on my GUI variable, like this:

class PlayerCharacter(types.KX_GameObject):
    def __init__(self, own):
        # Get Current Scene
        self.current_scene = logic.getCurrentScene()


        # Get Game Controller
        self.game_controller = self.current_scene.objects['new_GameController']
        
        #etc. etc. etc.
        
        self.gui = None


        # Get GUI
        for s in logic.getSceneList():
            print(s)
            if s.name == 'GUI':
                self.gui = s
            else:
                self.gui = None

The problem is, sometimes self.gui has a reference to the GUI scene, sometimes it doesn’t. Any clue as to what might be happening?

You should insert a break statement after you save the GUI scene. Otherwise if there are more scenes after it, you will overwrite self.gui with None. Also make sure you’re not running this code on the same frame you add the GUI scene. Newly added scenes won’t show up in the getSceneList until the frame after they have been added.

Oh god! Thank you! -.- that was a pretty stupid mistake that I made right there