How to send a RPC for this client but on server

Options
Hello, i have some trouble with my script and i hope you can help me.
I have an item/inventory system but the problem is, if 2 people pick the item in the same time with some ping, the 2 player can take the item, so i do my stuff like that thinking it's gonna resolve my problem :
[PunRPC]
	void Pickup ()
	{
		int id = rayObject.gameObject.GetComponent<Pickup> ().itemID;
		if (id != null && rayObject.gameObject.layer == 8) 
		{
			if (rayObject.GetComponent<PhotonView> ().instantiationId == 0) 
			{
				Destroy (rayObject.gameObject);
			} 
			else if (rayObject.GetComponent<PhotonView> ().isMine) 
			{
				PhotonNetwork.Destroy (rayObject.gameObject);
			}
			inventory.AddItem (id);
		} 
		else 
		{
			Debug.Log ("Item picked up in same time (but don't work)");
		}
	}
So the rayObject it's a raycast who return the ID and the Layer of the gameObject (Layer for know if its an item, and ID for know who item to add in inventory)
That's my RPC call
photonView.RPC ("Pickup", PhotonTargets.AllViaServer);
the problem is all the player launch the function Pickup if one launch it, how i can do for not 2 people can take an inventory if he have some ping ?
Im really stuck, thanks in advance for any help !

Comments