[Photon] How would I give each player a different variable?

So I’m new to Photon, and multiplayer in general so I’m sorry if this is a dumb question.
I’m trying to make a game where each player has a different role but I’m not sure how to go about doing that.

For Example, when the game starts, I want to give a random player a roleId of ‘0’, another one a roleId of ‘1’, and all others a roleId of ‘2’.

I tried having a look at RPCs but I’m not quite sure how they work and I don’t even know if it’s what I need.

Thanks.

The Photon tutorial (link below) goes through all the steps, starting with opening a lobby and connecting the players, then instantiating the player’s controllers. It uses GameManager to connect up the players via lobby etc but my instructions below should work - just adding another method on it. This assumes the GameManager doesn’t get destroyed when you load the scene for the players to be in.

You should go through a tutorial what will explain the basics first, but you need to add a PhotonView to a game object like maybe call it GameManager or RoleManager and then add a new script called GameManager as well as the PhotonView component to an empty gameobject. Naturally you need to do this to a gameobject that will be around once the game has loaded - in the game scene. In your GameManager script you declare a method as [PunRPC] and only in your host code do you call the:

PhotonView photonView = PhotonView.Get(this);
photonView.RPC(“ChatMessage”, RpcTarget.All, “jup”, “and jup.”);

You should understand that code in the GameManager runs on all machines, whether its a host or client. You want the host to call those two lines of code. The parameters don’t have to be strings, you can set them to integers or just have one integer parameter. The point is that the clients will have their ChatMessage function called with the parameters you sent.

So you might call it SetRole instead of ChatMessage.

This link shows the most basic RPC described above:

There isn’t much to it, you define the method and decide what to send to the method as parameters. You add code to use the parameters once it is called. The little trick is understanding that all scripts will be running on all copies of all gameobjects on all clients. When you call photonView.RPC(“ChatMessage”, RpcTarget.All) every client individually will have their ChatMessage function run with the parameters you send.

Unfortunately your case is more complicated, you need a way to send messages to individual clients. Hopefully someone can answer that but you should understand the basics first.