#Multiplayer coding help

1 messages · Page 1 of 1 (latest)

shy oar
#

Hi

#

so this is my first time working on a multiplayer game and whenever I play as a host everything works fine but when I try to play as a client I get this error. I tried researching but didn't find anything useful so if anyone knows why I am unable to connect my client's to the host please answer.
Note : I am using ClientNetworkTransform instead of NetworkTransform for my gameobjects
As for the code I have this...

#
SpawnManager spawnManager;
NetworkVariable<int> carIndexPos = new(0);
 
public override void OnNetworkSpawn()
{
    base.OnNetworkSpawn();
    carIndexPos.OnValueChanged += OnCarIndexChanged;
    if (!IsOwner) { return; }
    SetClientSpawnPosition();
    SpawnRequestServerRpc();
}
 
void SetClientSpawnPosition()
{
    spawnManager = GameObject.FindGameObjectWithTag("Manager").GetComponentInChildren<SpawnManager>();
    transform.position = spawnManager.GetSpawnPosition(carIndexPos.Value);
}
 
//This method is a request from owner to server to set its spawn position
[ServerRpc]
void SpawnRequestServerRpc(ServerRpcParams serverRpcParams = default)
{
    carIndexPos.Value++;
    Debug.Log("Car Index is " + carIndexPos.Value);
}