How change scene and position with a door

Godot Version



Hello guys, I need some help with the doors in my game. Currently, I have a code that changes scenes after an input within the door area, however, I also need to set the player’s position when going to the other scene.

This is my code

extends Area2D

u/export_category("Next Scene")
u/export var next_position: Vector2

u/export_file var next_scene
var on_door := false
var on_scene := false

u/onready var alert := $alert as Label

func _on_body_entered(_body: Node) -> void:
_player_ref = _body
on_door = true 
#Global.from_level = get_parent().name

func _on_body_exited(_body: Node):
on_door = false

func _process(delta: float) -> void:
if on_door and Input.is_action_just_pressed("interaction"):
on_scene = true
if on_scene == true:

func _on_scene_changed():
var alli = get_tree().get_node("Ysort/Alli")
alli.position = next_position

When you call change_scene_to_file the currently active scene will be replaced with the new scene. If you want to share information between the two, you need to do so in a place that is not swapped out. An Autoload should do the trick.