room script of the rails

Godot Version

4.3

Question

making a deltarune fangame but im stuck on the room system since i want a clear hiearchy i cant just use chane_scene_from_file/packed() so im trying to do it via a singleton but every time i try to enter a room it returns this error Cannot call method ‘instantiate’ on a null value.
i can show some of my code here

singleton called Single.tscn original i know

extends Node

@onready var state:String


signal battle
# Called when the node enters the scene tree for the first time.$kris, $kris/Camera2D, $Tem$kris, $kris/Camera2D, $Templa$kris, $kris/Camera2D, $Templ$$kriskrisate, $tempenemyte, $tempenemyplate, $tempenemy
func _ready() -> void:
	pass
	 # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	pass


func teleport(sceneroot,sceneinst:PackedScene,newloc:Vector2,player:CharacterBody2D):
	print("wowzers")
	print(sceneroot.name)
	print(sceneinst)
	print(newloc)
	#scenedel.queue_free()
	var tree = player.get_node("..")
	print(tree)
	
	#print(sceneinst.can_instantiate())
	var newscne = sceneinst.instantiate()
	
	tree.call_deferred("add_child",newscne)
	player.position = newloc
	newscne = null

area2d node called area_teleport.tscn
as you can tell by this mess of spaghetti code i have tryed a lot of approaches the deleting of the camera is because of position smoothing and drag

extends Area2D

@onready var timer: Timer = $Timer


@export var newlocation: PackedScene
@export var newlocinscn : Vector2
# Called when the node enters the scene tree for the first time.
# Load the scene as a PackedScene
var scene = preload("res://scenes/camera.tscn") # Replace with your scene path

# Instance the scene
var instance = scene.instantiate()


# Get the node you want to add the scene to

func getcam(searched):
	var searchedchilderen = searched.get_children()
	for i in searchedchilderen:
		if i is Camera2D:
			var camera = i
			print(i)
			return camera

func _ready() -> void:
	pass
	

func _on_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		var _nodepathbody = get_path_to(body)
		Single.teleport(get_tree().current_scene,newlocation,newlocinscn,body)
		get_parent().queue_free()
		
		#var camera = NodePath("body/Camera2D")
		#var cameranode = get_node(camera)
		#print(body)
		##print(camera)
		#var camera = getcam(body) 
		#
		##if cameranode is Camera2D:
		#camera.queue_free()
		#body.global_position = newlocation
		#print("deleted")
		#var scene = preload("res://scenes/camera.tscn") # Replace with your scene path
		## Instance the scene
		#var instance = scene.instantiate()
		#body.add_child(instance)
		#instance.name = "Camera2D"
		#print(newlocation)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	pass

player for all that helps (characterbody2d of course)

extends CharacterBody2D

@onready var _animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D



@export var SPEED = 100
@export var DARK = false

# Called when the node enters the scene tree for the first time.
func doabattle():
	print("wow its a battle scene")

func _ready() -> void:
	var _animationstart = _animated_sprite_2d.animation
	_animated_sprite_2d.stop()
	Single.battle.connect(doabattle)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	var inputvector = Input.get_vector("left","right","up","down")
	
	
	if Input.is_action_pressed("down"):
		_animated_sprite_2d.play("walk south"+"_"+var_to_str(DARK))
	elif Input.is_action_pressed("right"):
		_animated_sprite_2d.play("walk east"+"_"+var_to_str(DARK))
	elif Input.is_action_pressed("left"):
		_animated_sprite_2d.play("walk west"+"_"+var_to_str(DARK))
	elif Input.is_action_pressed("up"):
		_animated_sprite_2d.play("walk north"+"_"+var_to_str(DARK))
	else:
		_animated_sprite_2d.stop()
	
	
	if Input.is_action_pressed("deny"):
		velocity = inputvector * SPEED * 1.5
	else:
		velocity = inputvector * SPEED
	move_and_slide()

please help im banging my head against a wall like a fly trying to solve this

func teleport(sceneroot,sceneinst:PackedScene,newloc:Vector2,player:CharacterBody2D):
...
	var newscne = sceneinst.instantiate()

I am guessing this is the line with the error?
You call teleport with the following line:
Single.teleport(get_tree().current_scene,newlocation
newlocation is an exported variable without a default value. Did you remember to assign it a value in the editor?
Print out that variable just before the teleport call and see what it contains.

As a side note, your variable naming style is perplexing me and probably not helping you as you debug your own code.
Some examples:
var newscne Is saving on typing 1 character an advantage? No, it is a disadvantage. If it hasn’t already, it probably will lead to an error (despite being easy to find and fix)

@export var newlocation: PackedScene
@export var newlocinscn : Vector2

Here we have a crossover. “Location” is read into both these variables despite it being shortened in the second variable (new location in scene).
One word, two different meanings, two different entities. Is location a vector or is it a scene?
newlocation is typed as a PackedScene. How about new_scene instead?
And then when it gets to the teleport function it becomes sceneinst ostensibly ‘scene instance’. But it isn’t a scene instance. It is a PackedScene.
In teleport I would call it closer to what it is; again new_scene.

newlocinscn is vector. Every positionable node in Godot uses ‘position’. How about new_position?

I use landing_zone to denote where in a scene a character body is transitioned to in a new scene.
Instead of a simple vector 2, I create a scene using a Marker2D as the parent node. Instance that scene in the editor and visibly place it where I want it. You can get the Marker2D’s global position when you want the Vector.
Just my 2 cents.

Coming from style guides of different languages GDScripts style guide was at first a bit off putting. But I have adopted some of the recommendations and I link it here for your consideration.

ok yes i have to admit my naming conventions aren’t ideal but dor me they work i do not want to teleport but go to another room in a position i need multiple positions because a room can have multiple doors so you need to be able to appear in all of them
yes the newlocation variable is an export without a default i can check that i also got the idea to make the packedscene a string or a resource path so maybe that will work

i fixed it kind of i still needs a bit of work but loading it from 1 export wasnt smart resource path was the way to go