Client game scene can't find node when Server can

Godot Version



I have been working on a 2D multiplayer game and have run into a roadblock. I am currently trying to make it so that when the host starts the game, the game scene loads and all of the players are created at their respective spawn points. I’m currently using the MultiplayerSpawner node to spawn all of the players in, but I’m having issues. I’m spawning in the players with a script in the game scene, and whenever the server does it everything goes fine. But the moment a player tries to create a player instance it gives me a get_node error:

E 0:00:21:0154 get_node: Node not found: “Game/MultiplayerSpawner” (relative to “/root”).
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1651 @ get_node()

I can not for the life of me figure out why this is happening. It works flawlessly when the server runs it. But the moment a client tries to get a reference to the MultiplayerSpawner node it can’t find path. Here’s the game scene script:

extends Node2D
@onready var spawnLocations = ["SpawnP2","SpawnP1","SpawnP3","SpawnP4"]
const PLAYER = preload("res://Scenes/player.tscn")
@onready var spawner = $MultiplayerSpawner
func _ready():
	spawner.spawn_function = spawnPlayer
	if not multiplayer.is_server():return
func startGame():
	var i = 0
	for id in Global.playerList:
		print("Spawning player number ",i+1,". ID: ",id)
        #I have multiple spawn locations, this works fine. I've tested it.
		var spawnNodePath = NodePath(spawnLocations[i])
func spawnPlayer(_id: int):
	var player = PLAYER.instantiate()
	player.set_multiplayer_authority(_id) = _id
	return player

I’m ripping my hair out at this point. If you have any ideas of why this isn’t working please do tell. If you think I should post a problem on github I’m more than happy to.

how are your players connecting? Are you sure they have the same scene loaded? I would bet the set_spawn_path needs to be synced between client and server, so your spawnPlayer function should change the player’s position to the nodes instead of attempting to parent them.

They do have the same scene loaded. The problem is not with the spawn path. It seems like it’s failing at getting the MultiplayerSpawner node. But I will look into it. Also in hindsight setting the position is probably a lot smarter than parenting them, you’re right. But, again i don’t think that’s what’s causing the problem. Thank you for your input.