Destroying entire parent object on one client but on the other destroying just the child.

This is going to be a lot of text but i really need help so please try to bare with me. I am currently making a multiplayer space combat building game (kinda like space engineers). I need the parts to be destroyed when they take damage. The problem is when one part takes enough damage to be destroyed, to the player who shot the other ship the entire ship is destroyed when one part dies. But to the player who has been shot, it works fine and only one part is destroyed. Another strange thing is that to the player who has been shot, the other players ship is gone too. I have a photon view observing the parts script on each part. I'm going to post the important parts of the script in order of what happens.

To start here is the bullet script.
   void OnTriggerEnter(Collider othercol) {
    		if (othercol.gameObject) {
    			if (gameObject != ShooterShip) {
    				Debug.Log (othercol.name);
    				if (othercol.GetComponent<Parts> () != null) {
    					othercol.GetComponent<Parts> ().GetComponent<PhotonView> ().RPC ("TakeDamage", PhotonTargets.AllBufferedViaServer, damage);
    					//PhotonNetwork.Destroy (this.gameObject);
    				} else {
    					//PhotonNetwork.Destroy (this.gameObject);
    				}
    			}
    			//PhotonNetwork.Destroy (this.gameObject);
    		}
    	}
This checks if the bullet hits a gameObject with the parts script and tells that's parts script to "TakeDamage".

The next is the Parts script.
  [PunRPC]
    	public void TakeDamage(float damage) {
    		PartHp -= damage;
    		transform.parent.GetComponent<FlightSystem> ().GetComponent<PhotonView> ().RPC ("DestroyPart", PhotonTargets.AllBufferedViaServer);
    	}
This subtracts the hp from the individual part and tell the main flight script to calculate if any part is destroyed. Next is the flight scripts calculations.

    	[PunRPC]
    	public void DestroyPart(){
    		foreach (GameObject p in PartsGO) {
    			if(p.GetComponent<Parts>()){
    				if (p.GetComponent<Parts> ().PartHp <= 0) {
    					if (p.GetComponent<Parts> ().CockPit == true) {
    						NetworkManager nm = GameObject.FindObjectOfType<NetworkManager> ();
    						nm.standbyCamera.SetActive (true);
    						PhotonNetwork.Destroy (this.gameObject);
    					} else {
    						PhotonNetwork.Destroy (p.gameObject);
    					}
    				}
    			}
    		}
    	}
This checks the list of parts and sees if any part has an hp of less than 1. If it does it is suppose to destroy the single part. Please help i have been trying to get this is works for days.
Sign In or Register to comment.