I have a code that basically load a new scene. To do that it needs to unload the previous one but for some reason, it keeps the previous scene and also loads the new one, running both scenes.

What's wrong guys?

get_tree().get_root().remove_child(s1)
stlevel = load("res://world/level_001/level_001.tscn").instance()
			
get_tree().get_root().add_child(stlevel )

You need to add the following after remove_child(s1):

s1.queue_free()

The remove_child function just removes the node from being parented, but it does not remove it from the scene. queue_free will remove the node from the scene. (Side note: You shouldn’t need to call remove_child if you use queue_free, I think)

Thanks so much, I've tried but in my case didn't work, however, I found the solution with a new func

now I have a bigger problem: I have a code properly work on level1 but loading the level 2 any calls to a scene calls "HUD" doesn't work anymore get_tree().get_root().get_node("MainScene2D").get_node("Player").score = player_score get_tree().get_root().get_node("MainScene2D").get_node("HUD").get_node("Hud").get_node("ScorePanel").get_node("Score").text = str(player_score) $Timer.start()

for instance

2 years later