How do I switch scenes and get the objects in the new scene to interact

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

I’ve been trying to make a pong clone but I’m struggling with switching to a “You Win” screen. I can switch to it by using “get_tree().change_scene(“res://WinScreen.tscn”)” but I want it to display the score and have a ball bouncing around but instead the score isn’t working and the ball stays still. If I just load the scene though, it works as intended. I use GDScript and will attach a video below.

:bust_in_silhouette: Reply From: crossbito

Hello, maybe I’m wrong, but it seems like you placed the “changescene” function inside the ball. The ball is also present in the winscreen, so when you change scenes, the ball keeps instantiating the same scene repeatedly. This prevents the score from updating form 0 becouse you instance the scene first and change the value in screen later, and the ball remains in the initial position.

When you run the WinScreen, the global variables for both scores are set to 10. That’s why you don’t encounter any problems there, as your condition checks if either score reaches 11 to switch the scene.

That’s my theory.