How to set a variable equal to another variable in another gameobject?

What I’m trying to do is a build a system where the player can see a weapon on the ground, it clones a new weapon and carries all the set variables over to that clone (ammo etc), pick up the clone, and that should replace the other weapon they’re already holding.

My other game object is called Weapon Controller, and that has the script called weaponHandler, which has all the code used to hold any weapon it’s given and switch between the two of them. weaponHandler has to two variables, one for each weapon.

Any help I can get I’d appreciate :')

#pragma strict

var weapon : GameObject; //any weapon can be used here
var currentClip : float;
var currentAmmo : float;
var currentWeapon : Component;

function Start ()
{

}

function OnTriggerEnter (other : Collider) 
{

    print("Item is in range");
    var weaponClone : GameObject = Instantiate (weapon); //clone the weapon
    currentWeapon = gameObject.GetComponent(WeaponHandler); //check what weapon is in the weapon1 variable
    currentWeapon.weapon1 = weaponClone; //change that current weapon to our new cloned weapon
    //var currentSelected = currentWeapon.GetComponent(WeaponHandler).weapon1;
    //currentSelected = weapon;
    
    
}

If you’re asking the almost-question in the title:

someGameObject.GetComponent(TypeName).variable = aValue;

or

aVariable = someGameObject.GetComponent(TypeName).variable;

GetComponent is “slow”, so if you’re going to use it a lot it’s better to cache the value as a reference:

var typeName : TypeName = someGameObject.GetComponent(TypeName);

typeName.variable = value;

Thanks I tried that out but had no success, I ended up trying something else which I thought would work.

Problem is it now says “An instance of type “WeaponHandler” is required to access non static member ‘weapon1’”. I changed the weapon1 variable to static, compiled, but of course changes everything, any idea for a solution around this? I’m not sure how to set the appropriate access between it all.

#pragma strict

var weapon : GameObject;
var currentClip : float;
var currentAmmo : float;
var currentWeapon : GameObject;

function Start ()
{

}

function OnTriggerEnter (other : Collider) 
{
	var weaponClone : GameObject = Instantiate (weapon); //clone the weapon
    print("Item is in range");
    WeaponHandler.weapon1 = weaponClone;
    WeaponHandler.weapon1 = currentWeapon;