Function called on host but not on clients

The situation here is simple, player shoots bullet of random size, for debugging purpose I print the size of bullet from both Player 1(host) & Player 2 (Client), the size is printed correctly for both Players 1 & 2 on the host screen but not on the client screen.

here’s my code:

[Command]
public void CmdFire(){

shooterG = transform.GetChild (0).gameObject;
GameObject bullet = Instantiate (bllt, shooterG.transform.position, shooterG.transform.rotation) as GameObject;

bullet.GetComponent ().velocity = shooterG.transform.right * 20;

bullet.transform.localScale = transform.localScale;

if(isLocalPlayer)
pl1.text = "1. " + bullet.transform.localScale.ToString (); //prints size of bullet from player 1

if(!isLocalPlayer)
pl2.text = "1. " + bullet.transform.localScale.ToString (); // prints size of bullet from player 2

NetworkServer.Spawn (bullet);

Destroy (bullet, 10);
}

P.S: how do you embed code here in the forums, I don’t know so I copy-pasted.

Well, everything in a command is ran on server? So that’s server code, thus only runs on the server

Then what should I do, pls guide me

I don’t know what you need to accomplish.

I need to display the size (transform.localScale) of 2 players

Generally you’d use clientRPCs or syncvars to send this information to the clients from the server. Though you could just put this stuff in the Start() on the bullet itself, which will be run on all clients when the bullet spawns. Like when you instantiate the bullet you could set a syncvar on it that says what player number it is. Then when the bullet spawns on each client, the bullet’s start() could update whatever you’re trying to do with transform.localscale.

1 Like

will try this