Invalid access to property or key on a base object of type null instance

context: im making a main menu and my quit button has this error and ive been trying random stuff heres the code the problem is bolded class_name MainMenu
extends Control

@onready var start_button: Button = $MarginContainer/HBoxContainer/VBoxContainer/start_Button as Button

@onready var quit_button: Button = $MarginContainer/HBoxContainer/VBoxContainer/quit_Button2 as Button

@onready var start_level = preload(“res://pause_menu.tscn”) as PackedScene

func _ready():
start_button.button_down.connect(on_start_pressed)
quit_button.button_down.connect(on_quit_pressed)

func on_start_pressed() → void:
get_tree().change_scene_to_packed(start_level)
func on_quit_pressed() → void:
get_tree().quit()

Are you sure this is spelled correctly and that the node is indeed placed in the correct position inside the scene tree?

1 Like

welp uhhhhhhhhh i guess i overcomplicated it lol thanks for pointing it out.