if the ball hits the coin the coin need to be destoyed but how? i have this but it does not work.

#pragma strict

function OnTriggerEnter (name : Collider)
{
	if(name.tag == "Player")
	{
		Destroy(gameObject);
	}
}

In your script, the “gameObject” reference will refer to the object the script is attached to. So, if the script is attached to the player, that’ll destroy the player. If you want to destroy the object you collided with, you want this instead:

Destroy(name.gameObject);

@Hoogstra i see now you are using OnTriggerEnter wich is a 3d detection function and you are destroying the player game object not the coins which is not happening now because of the fierst problem & the coins tag is not “Player” so you need this :

function OnTriggerEnter2D(other: Collider2D)
{
     // you have to tag the coins game object  i am not sure if you did it 
     if(other.tag == "Coin") 
     {
         Destroy(other.gameObject);
     }
}