How to add a component to a prefab

I am trying to add a component to a prefab but I can’t get it to work. I want the component to be added only when I join a room (multiplayer). This is the code that I have right now.

var pms : PlayerMovementScript;

function OnJoinedRoom()
   {    //Initialize the player and add components
       player = PhotonNetwork.Instantiate("Player Capsule",, Quaternion.identity, 0);
       pms = player.AddComponent("PlayerMovementScript");
       pms.enabled = true;
       myPlayerPv = player.GetComponent(PhotonView);

I want it to be added only when I join the room so that I can control only my player. The component that I am trying to add is the PlayerMovementScript. Thanks.

You don’t need to attach a script for this to work. You can add one but be aware that remote players won’t do the same! RPCs and OnSerializePhotonView() should be defined in scripts that are active on all clients.

If you want to control only your own character, simply check the PhotonView.isMine property.
This will be true for the GOs a user instantiated and also for the scene objects on the client that is the MasterClient. Only PhotonView’s that belong to a player have a valid user though.

In the Marco Polo Tutorial, we use isMine and also show another way to keep control over “owned” objects: