Invalid call. Nonexistent function 'play' in base 'Nil'

Godot 4.4

The problem is that during pause it crashes as the level music it doesn’t know what to do with it?

Game manager.gd
extends Node

signal gain_coins(int)
signal gain_life(int)
signal lost_life(int)
signal gain_points(int)
signal level_beaten()

var coins : int
var score : int = 0
var lives : int = 0

var current_checkpoint : Checkpoint
var win_screen
var score_label
var music_position = 0
@onready var pause_label = $Pause
@onready var level_music = LevelData.level_music

var player : Player

var spawn_point: Vector2
@export var player_mode: Player.PlayerMode
var points_global = 200
var coins_global = 50
var lives_global = 5
var time: int

# Coins reach this number a 1up is given
const num_coins_for_1up: int = 100

# maximum number of lives that mario can have. --------------------------------
const max_num_lives: int = 99

# maximum number of coins that mario can collect at once ----------------------
const max_num_coins: int = 100

func respawn_player():
if current_checkpoint != null:
	player.position = current_checkpoint.global_position
	
func restart():
coins = 0
score = 0
lives = 5
get_tree().reload_current_scene()

#func load_world():
#get_tree().change_scene_to_file()

#func quit():
#get_tree().quit()

func on_life_collected(life_gained):
lives += life_gained
emit_signal("gain_life", life_gained)

func lose_life(life_lost):
lives -= life_lost
emit_signal("lost_life", life_lost)

func on_points_scored(points_scored):
score += points_scored
emit_signal("gain_points", points_scored)

func on_coins_collected(coins_gained):
coins += coins_gained
score += 100
emit_signal("gained_coins", coins_gained)
if coins == num_coins_for_1up:
	on_life_collected(1)
	coins = 0

func swap_pause_state():	
if not pause_label.visible:
	pause_label.show()
	music_position = level_music.get_playback_position()
	level_music.stop()
	Engine.time_scale = 0
	get_tree().paused = true
else:
	get_tree().paused = false
	level_music.play(music_position)
	Engine.time_scale = 1
	pause_label.hide()

I don’t know what to do as it wont pause my game and crashes. the Level_music in the LevelData script is an AudioStream var.

Do you maybe switch scenes, or do something else which might cause the thing level_music is pointing at to go out of scope and get freed?

Are you calling swap_pause_state before this node is ready? Is LevelData ready before this node is ready? Maybe it would be better to get the variable as it’s needed i.e. alway using LevelData.level_music.play