RPC called by OnPhotonPlayerConnected doesn't work

this is my sript I use for opening doors. when new player connects, I need to tell him whether the doors are closed or open. I wanted to send rpc to close the door when anyone connects if the doors are closed, but nothing happens

using UnityEngine;
using System.Collections;

public class door_interact : Photon.MonoBehaviour {
	
	public int speed = 4;
	public string axis = "z";
	public float coord1 = -10.12562f;
	public float coord2 = -15.18888f;
	public float coord3 = -4.210109f;
	public float coord4 = 0.9528589f;

	public void OnLookEnter()
	{
		if(Input.GetKeyUp("e"))
		{
			if (gameObject.transform.root.GetComponent<ship_stats>().door_locked == false)
			{
				gameObject.GetComponent<PhotonView>().RPC("open_close",PhotonTargets.All);
			}
		}
	}

	public void OnPhotonPlayerConnected ()
	{
		gameObject.GetComponent<PhotonView>().RPC("open_close_update",PhotonTargets.All);
	}

	[RPC]
	public void open_close()
	{
			if(gameObject.transform.root.gameObject.GetComponent<ship_stats>().door_bridge_open == true)
			{
				iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_left").gameObject,iTween.Hash("islocal",true,axis,coord1,"time",speed));
				iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_right").gameObject,iTween.Hash("islocal",true,axis,coord3,"time",speed));
				gameObject.transform.root.gameObject.GetComponent<ship_stats>().door_bridge_open = false;
			}
			else
			{
				iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_left").gameObject,iTween.Hash("islocal",true,axis,coord2,"time",speed));
				iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_right").gameObject,iTween.Hash("islocal",true,axis,coord4,"time",speed));
				gameObject.transform.root.gameObject.GetComponent<ship_stats>().door_bridge_open = true;
			}
	}

	[RPC]
	public void open_close_update()
	{
		if(gameObject.transform.root.gameObject.GetComponent<ship_stats>().door_bridge_open == false)
		{
			iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_left").gameObject,iTween.Hash("islocal",true,axis,coord1,"time",speed));
			iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_right").gameObject,iTween.Hash("islocal",true,axis,coord3,"time",speed));
			gameObject.transform.root.gameObject.GetComponent<ship_stats>().door_bridge_open = false;

		}
	}
}

When the second player joins, I’m assuming that: door_bridge_open == true for that very client, seeing since the only way you set it to false is with the first player by pressing e, right?

However, the second player has not received this information, if it has been set to false, while the second player still hasn’t joined the game.

Whenever a new player connects it checks if it is false, which it cannot be unless it is stated so at the start of the application or he receives data about what has happened in the game before he joined.

Hope this is somewhat a help to you. If not, you should try and post it on the Exit-Games forum (Photon’s own). They are usually very helpful.

Good luck.

Don’t forget to drag and drop your script (NetworkDoor) to your Photonview script in the inspector…

1- drag and drop your door object
2- drag and drop your network door script

It should send your variable correcly