# Only host can spawn object

I am currently making a multiplayer game however only the host has the capability to spawn projectiles.

[Command]
void CmdSpawnEgg()
{
if (cam == null)
{
return;
}
GameObject instance = Instantiate(eggPrefab, transform.position + (transform.forward * offset), cam.rotation);
NetworkServer.Spawn(instance);
}


//cam is the transform of the players camera and if its not the local player the camera is destroyed

The projectile is also a registered spawn-able prefab for the network manager

• Try checking if cam is null on your client player. Or just check for isLocalPlayer – TehMightyPotato Mar 14 '19 at 9:35
• this was the problem i was destroying the camera if it wasnt the local player but that made the server unsure of where the bullet was supposed to come from – Omari Lawrence Mar 14 '19 at 18:51
• nice! glad you figured it out. – TehMightyPotato Mar 15 '19 at 8:36