How to use RPC to determine class?

I’m trying to make it so that the first player to connect to a server will be assigned a particular controller and subsequent player will be assigned a different controller. I’ve set up a series of @RPC calls which should update variables which determine which controller the player spawns. However, players always spawn with the first controller. Here is my abridged code:

var isRTS : boolean=false;
var hasPlayer : boolean=false;

...

function OnServerInitialized(){
	Debug.Log("Server initialized");

		if(isRTS == false){
			Debug.Log("No RTS Player.");
			spawnRTSPlayer();
		}
		else
		Debug.Log("RTS Player Present.");
		spawnPlayer();
	
}

function OnConnectedToServer(){
	
		if(isRTS == false){
			Debug.Log("No RTS Player.");
			spawnRTSPlayer();
		}
		else
		Debug.Log("RTS Player Present.");
		spawnPlayer();

}

...

function spawnPlayer(){
	if(hasPlayer == false){
		Debug.Log("Spawning Player");
		GetComponentInChildren(Camera).enabled = false;
		Network.Instantiate(playerPrefab, playerspawn.position, Quaternion.identity, 0);
		networkView.RPC("HasPlayer", RPCMode.AllBuffered);
	}
		
}

function spawnRTSPlayer(){
	if(hasPlayer == false){
		Debug.Log("Spawning RTS");
		GetComponentInChildren(Camera).enabled = false;
		Network.Instantiate(RTSPrefab, rtsspawn.position, Quaternion.Euler(50, 0, 0), 0);
		networkView.RPC("RTSPlayerCount", RPCMode.AllBuffered);	
		networkView.RPC("HasPlayer", RPCMode.AllBuffered);
	}
	
}

@RPC
function RTSPlayerCount(){
	Debug.Log("UpdatingRTSCount");
	isRTS = true;

}

@RPC
function HasPlayer(){
	Debug.Log("UpdatingHasPlayer");
	hasPlayer = true;

}

Can anyone see why this wouldn’t be working? Thanks.

Hi!

You have a couple problems with your code, One is the theroy.
What you are trying to do is sync a variable constantly and then take action accordingly clientside. But you can never be sure what happens clientside. Instead of syncing a variable from the server to all clients, why not only have it on the server? When someone wants to spawn he then sends an RPC to the server, which sends back an RPC for which type of player to spawn.

Another is the random else thats bugging me on line 25. Right now it dodes nothing, but I think it probably should.
Don’t forget the {} :stuck_out_tongue:

Hope this helps, Benproductions1