Instantiate New Gun

I am trying to make a gun pick up script so. So far I have it so that if I press right mouse click it will instantiate my gun prefab as a child of where the gun spawned from. the only problem is that when I run it and right click I get an error that says

“Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.”

I don’t know what to do someone please help me. Here is my code

var gun : Transform;


function Update () 
{
	if (Input.GetButtonDown("Fire1")) 
	{
		
   		Instantiate(gun, transform.position, transform.rotation);
   		transform.parent = gun.transform;
	}
}

You are parenting the prefab rather than the new instance. Do this

if (Input.GetButtonDown("Fire1")) 
{

    var newGun=Instantiate(gun, transform.position, transform.rotation);
    transform.parent = newGun.transform;
}