Get_tree() is returning null?

Godot Version

4.2.2

Question

I’m trying to add an error function to my game that resets the round if something that would cause the game to softlock occurs. For this, I’m using the scoring logic that is already present in the game, just without adding a point. So a message pops up stating there’s an error, and then the scene is reloaded. However, when it is called passing the error variable, the game crashes when it tries to reload because get_tree() is returning a null value, even though get_tree() is used just before that to start a timer to wait for!

What the heck? How is get_tree() turning into null in those few frames, and only when team == “error” ??? Here is the function in question:

@rpc("authority", "call_local", "unreliable")
func display_score_message(team):
	
	# Set the font size
	score_label.add_theme_font_size_override("font_size", 600)  # Adjust the size as needed
	#Check for errors that require a round restart
	if team == "error":
		score_label.text = "Resolving Technical Issue"
		score_label.add_theme_font_size_override("font_size", 300)
	else:
		# Change the text of the score_label
		score_label.text = team.capitalize() + " Scores!"
	
	# Center the label text
	score_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
	score_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
	
	# Change the text color based on the team
	if team == "blue":
		score_label.add_theme_color_override("font_color", Color.DEEP_SKY_BLUE)  # Blue color
	elif team == "red":
		score_label.add_theme_color_override("font_color", Color.RED)  # Red color
	else:
		score_label.add_theme_color_override("font_color", Color.YELLOW)
	
	# Make the label visible
	score_label.visible = true
	
	# Disable players for a moment
	disable_players(5.0)
	
	# Wait for a moment before hiding the label
	await get_tree().create_timer(2.0).timeout
	score_label.text = ""
	for player in player_nodes:
		player.save_cooldowns()
	get_tree().reload_current_scene()

I have found on the odd occasion the tree may return as null before it is fully loaded or when moving to a different scene. I use the below to check on those rare occasions. Place whatever you need in the if I only ever need to check for a pause.

# Make sure the tree is not null
	if is_inside_tree():
		get_tree().paused = false