Multiplayer projectiles problems!

I’m working on a multiplayer game were you can shoot projectiles at other players. I however ran into a problem. When the player clicks a button a projectile is instantiated in the game and travels in the direction the camera was facing, but when it collides with an enemy player it deals damage twice. I tried solving the problem for a couple of days now but with no luck. Could anyone please tell me what I’m doing wrong?

#pragma strict

var onHitEffect : GameObject;

var damadge : int;

var speed : float = 50;
var size : Vector3;
var directionDistance : float = 50;
var directionCurve : AnimationCurve;
var directionStrength : Vector2 = Vector2(0, 0);
var directionStrengthMulti : float;

var savedRot : Vector3; 


@HideInInspector
var keepMoving : boolean = true;
@HideInInspector
var time : float;
@HideInInspector
var screenPos : Vector3;
@HideInInspector
var hit : boolean = false;

//////////////////// I left out the code that makes the projectile move forwards because it just takes up space and isn't the problem

function OnNetworkInstantiate (info : NetworkMessageInfo) {
    if (networkView.isMine)
        Debug.Log("New object instanted by me");
    else
        Debug.Log("New object instantiated by " + info.sender);
}


function OnCollisionEnter(collision : Collision) {

	if (collision.gameObject.tag == "Player"  networkView.isMine){  // Cheks if it hi a player an if the object belongs to us
	
		var playerScript = collision.gameObject.GetComponent(Player);
			
			playerScript.networkView.RPC("TakeDamadge", RPCMode.All, damadge); // tells everone to take damadge
			//playerScript.TakeDamadge(damadge);
			Debug.Log("Hit player for" + damadge);

	
	}
	
	if (onHitEffect){
	
		var contact : ContactPoint = collision.contacts[0];
		var rot = Quaternion.FromToRotation(Vector3.forward, contact.normal);
		
		Instantiate(onHitEffect, contact.point, rot);	
	
	}
		
	
		Destroy (gameObject);


}

right after you send damage you should destroy the bullet, that’s why maybe it’s sending it twice. now you aren’t showing your damage script too or function

if it was C# it would be better. but Try sending the RPC to othgers buffered. And show us your TakeDamage Method.

Did you try oncollisionstay?

Remove collider when prefab isn’t instantiated by your authority (client or server)

Now, you are doing damage when colliding on each client independently, then sending it to others. (so 2 clients: 2 times damage, try it with 3 clients or more and you’ll get instant death :smile:)

So to fix it: only apply damage if netview.isMine or remove the collider when !netview.isMine