Only one player for the host but two for the client

Hello,
I recently try the Netcode SDK, i’ve followed drapperdino tutorial, and when i click on start the game i’ve created a very simple script in a gameobject called GameManager (object & script).
But when i start the game the client see 2 players but the host see only one players.
I’ve added the player prefab (literally a capsule with a camera behind) to Networked Prefab in NetworkManager.
And finally i’ve added a NetworkObject to the Player Prefab.
P.S.I don’t use the PlayerPrefab option in NetworkManager.

Here is my GameManager.cs

using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;

public class GameManager : NetworkBehaviour
{

    public GameObject PlayerPrefab;
    public float x1;
    public float x2;
    public float y;
    public float z1;
    public float z2;

    void Start()
    {
        Spawn();
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    private void Spawn()
    {
        GameObject SpawnBlock = GameObject.Find("StartLine");
        if (SpawnBlock == null)
        {
            Debug.LogError("Can't find starting line !");
        }
        else
        {
            x2 = (SpawnBlock.transform.localScale.x / 2) - 1;
            x1 = x2 * -1;
            y = SpawnBlock.transform.position.y + 1.5f;
            z2 = (SpawnBlock.transform.localScale.z / 2) - 1;
            z1 = z2 * -1;
            GameObject Player = Instantiate(PlayerPrefab, new Vector3((float)System.Math.Round(Random.Range(x1, x2), 0), y, (float)System.Math.Round(Random.Range(z1, z2), 0)), Quaternion.identity);
            Player.GetComponent<NetworkObject>().Spawn();
            Player.name = "Player_" + PlayerPrefs.GetString("PlayerName");

        }
    }
}

If someone help me

When the host connects, the code runs as expected. However when the client connects, it gets the host player object spawned automatically, and the code you posted instantiates a player object for the client – however, Start is only called on the new client, not on the server, and the server is the only one that can spawn an object over the network. You therefore need to make sure that Spawn runs on the server, for the client, and not on the client itself.

So where do i need to put the script ?

You have many options, but most commonly you would make Spawn() a ServerRpc that is called by newly connected clients. Putting a call to that in Start() might work, but I would put it in OnNetworkSpawn() to be safe. See also this thread for examples.

I replaced Start() Void by

public override void OnNetworkSpawn()
    {
        Spawn();
    }

And now it doesn’t work, nobody spawn

Is GameManager not a NetworkObject? I recommend you reread my post and the linked thread – you need to make sure that Spawn() is a ServerRpc, only the server should be instantiating and spawning players.

Now i have a NullReferenceException: Object reference not set to an instance of an object
For this part of code:

[ServerRpc]
    private void SpawnServerRpc()
    {

        MainCamera.SetActive(false);
        GameObject SpawnBlock = GameObject.Find("StartLine");
        if (SpawnBlock == null)
        {
            Debug.LogError("Can't find starting line !");
        }
        else
        {
            x2 = (SpawnBlock.transform.localScale.x / 2) - 1;
            x1 = x2 * -1;
            y = SpawnBlock.transform.position.y + 1.5f;
            z2 = (SpawnBlock.transform.localScale.z / 2) - 1;
            z1 = z2 * -1;
            GameObject Player = Instantiate(PlayerPrefab, new Vector3((float)System.Math.Round(UnityEngine.Random.Range(x1, x2), 0), y, (float)System.Math.Round(UnityEngine.Random.Range(z1, z2), 0)), Quaternion.identity);
            Player.GetComponent<NetworkObject>().Spawn();
            Player.name = "Player_" + PlayerPrefs.GetString("PlayerName");


        }
    }

And I call this function in Start()
What’s wrong in my code ?