How to solve weird rotation problem?

Hey, I’m just making a weapon switching script, I keep both my weapon as children of the main camera, but for some weird reason, as I walk or jump, the graphics inside the gun gameObject rotate and I can no longer see them. This does not happen when I switch off my script. To solve it right now I got a lateUpdate function placing their local rotation and position to 0, but would like to fix it the right way. Here is what I have of the script.
P.S. I’ve also tried searching for a switching script on the web, but the same thing happens.

var maxGuns : int = 4;
var guns : GameObject[];
var playerMovementScript : PlayerMovement;
var activeGun : int = 0;
var player : Transform;

function activateGun (gun : int){
playerMovementScript.currentGun.GetComponent(GunScriptNoSD).beingHeld = false;
guns[gun].GetComponent(GunScriptNoSD).beingHeld = true;
playerMovementScript.currentGun = guns[gun];

guns[gun].transform.localPosition = Vector3(0,0,0);


function Start () {
playerMovementScript = GameObject.FindWithTag("Player").GetComponent(PlayerMovement);
player = GameObject.FindWithTag("Player").transform;
playerMovementScript.currentGun.GetComponent(GunScriptNoSD).beingHeld = false;
for (var i = 0; i < guns.length; i++){
print (guns*.name);*

guns*.transform.localPosition = Vector3(0,0,0);*

playerMovementScript.currentGun = guns[0];
guns[0].transform.localPosition = Vector3(0,0,0);
guns[0].GetComponent(GunScriptNoSD).beingHeld = true;
activeGun = 0;


function Update () {
if (Input.GetButtonDown(“Switch”)){
activeGun += 1;
if (activeGun > guns.Length - 1){
activeGun = 0;
activateGun (activeGun);

check if all the axes(X,Y,Z) are the same for the gun and every object that you have…also center the orgins…