Problem with changing scenes with camera dependent controls

So, i wanted to make a game where you control a Ball Character which with you’re supposed explore a big world collect stuff ect. But for a lot reasons i have to change scenes, so i can continue working on it. the Script works just fine, but as soon as i change scenes, it has a problem; in line 118 of the script there is a variable that cannot be loaded, because (i think) it has been used before in another (the first scene the ball character was used first) scene:(. I don’t know how to solve this problem, so i can use multiple scenes in my game. I’ve been putting several months into it so it’d be great if someone could solve this issue. If i start the game off of the menu and start the game the game works. If someone could change a bit of off the script so it works or at least tell me how to fix it otherwise that’d be very very helpful. So thank you for any reply. I am gonna upload a blend file using the same script where i made a small Doorframe you can roll through, in which the game will change scenes.

I already posted this in another section of this forum, but i figured that it fits way better here.

Attachments

ballgame.blend (896 KB)

Problem fixed; Mobios who created this script adviced me to move the player and the scene variable into the main function and it works fine now.