Instantiated objects not showing on new clients [uNet]

I’m not the most skilled developer so I rely on tutorials a lot, however I can’t figure out this thing. I’m making a 2D multiplayer survival game with zombies that automatically spawn. That works fine, but when a new client joins the game, the zombies that had previously been instantiated won’t show on that client.
Here’s my code:

public class EnemySpawner : NetworkBehaviour
{
public float speed;
public GameObject enemy;

void Start()
{
	CmdInvokeSpawnEnemy();
}

[Command]
void CmdInvokeSpawnEnemy()
{
	InvokeRepeating("RpcSpawnEnemy", 1, speed);
}

[ClientRpc]
void RpcSpawnEnemy()
{
	float x = Random.Range(-20, Camera.main.pixelWidth + 20);
	float y = Random.Range(-20, Camera.main.pixelHeight + 20);

	Vector3 target = Camera.main.ScreenToWorldPoint(new Vector3(x, y, 0f));
	target.z = 0f;

	GameObject enemyToSpawn = Instantiate(enemy, target, Quaternion.identity);
	NetworkServer.Spawn(enemyToSpawn);
	//Instantiate(enemy, target, Quaternion.identity);
}

}

Could anyone alter my code to show me the fix please?

  • Jared

NetworkServer.Spawn(enemyToSpawn); should be called on server, you call it on connected clients, because it is in [ClientRpc] void RpcSpawnEnemy()