How to use a script on multiple gameobjects, then change a variable for one of them, but not the others VIA script?

So i’m making a 2d Shooter game with C#. and i’ve made multiple guns (for example a handgun and an assault rifle) , i attached the same script on both of these guns , and they both have the same variables but i changed them in the inspector so they have different characteristics. How can i change the assault rifle’s Damage without interfering with the handgun , after meeting a certain condition in-game?.

EXAMPLE:
The assault rifle’s damage is 50 , the handgun’s is 30. the player buys an upgrade for the machine gun to increase its damage by 10, how can i change the rifle’s damage without changing the handgun’s damage?.

i’ve looked for an answer for like 2 hours today and i’ve got nothing :(.
Thanks for any help!!.

Using the same script on different objects essentially means instantiating two different instances of it. Changing the value of the rifle won’t change the value of the handgun, because they’re two different instances. Depending on your system, some “Manager” for the weapons, or any other script, should have references to both weapons. On upgrade, just change the value of the one weapon, it won’t change the other.

The only way of having one value across several instances is called class variable (indicated by the static modifier), which means not the instance has that value, but the whole class does, so it’s the same for all instances that access it. But that’s just a side note.