Help Changing Scenes

Godot Version

3.5.3.stable

Question

So, with my limited coding knowledge, I’ve been having a hard time figuring out how to do scene changes. I want to be able to change the scene while keeping player information such as health, current ship, etc. Something simple like how a metroidvania does their room changes.

Right now I just have a simple way to change the scene, but I have no idea how to make it so I enter a scene within a certain area and with saved player stats.

Here's what I have currently
onready var entered = false

func _on_Area2D_body_entered(body):
	entered = true

func _on_Area2D_body_exited(body):
	entered = false

func _physics_process(_delta):
	if entered == true:
		if Input.is_action_just_pressed("Use_Door"):
			# warning-ignore:return_value_discarded
			get_tree().change_scene("res://systems/test_system_2/warp gates/WarpGate_TS_1.tscn")
	elif entered == false:
		pass

I have read some stuff that made me think that I may have to rework my code or file system.
Anywho, any help would be greatly appreciated!

This is what my code looks like for the Metroidvania I did last month.

class_name MapLevel2D extends Node2D

const PLAYER = preload("res://addons/dragonforge_game_template/example/test_character.tscn")

@export var spawn_point: Node2D
@export var level_music: Song

var player: Node


func _ready() -> void:
	process_mode = Node.PROCESS_MODE_PAUSABLE


func start(incoming_player: Node, incoming_spawn_position: String) -> void:
	show()
	if incoming_player == null:
		player = PLAYER.instantiate()
		player.set_physics_process(false)
		add_child(player)
	else:
		player = incoming_player
		player.set_physics_process(false)
		player.reparent(self)
	if incoming_spawn_position != "":
		for node in get_children():
			if node.name == incoming_spawn_position:
				print(incoming_spawn_position + " Found!")
				spawn_point = node
				break
	player.position = Vector2(spawn_point.position.x, spawn_point.position.y)
	player.set_physics_process(true)
	if level_music:
		level_music.play()
	Disk.load_game()
	player.show()

Is this script on the root node of a scene?

Also, not going to lie, my smooth brain is not picking this up very easily, lol.

Well there’s a lot there TBH. This script is just on each level, and what I use to load each level. The level loading script gets passed the level, and then it calls start(), passing in an incoming_player which is assumed to be some sort of Node, and the name of a Node in the level that is the name of a spawn_point placed in the map.

If the incoming_player is null it’s a new game, and I load a default player instance.

If the spawn_point is null, it is assumed that this is a new game, and the starting level has a default starting point. It can be a Marker2D or Marker3D. I typically use an Area2D or Area3D with a CollisionShape2D or CollisionShape3D just so I can see where it is when I’m level building.

I turn the player’s _physics_process() function off, then back on so it doesn’t move around on the map until it’s placed correctly.

If the level has music I play it.

Then I load the saved game. This restores anything in both the level and the player such as health, items, pickups on the map, etc.

Last thing I do is make sure the player is visible.

If you want to see all the pieces working together, I have a game template that you can see an example of it working.

Someone else might have something simpler to show you. This is just what I’ve got.