Script won't set right rotation?

So i have this script where I want to set the localrotation and the localposition of my gun when picked up. The localposition works but setting localrotation won’t set it do what I want it too unless it’s 0.

using UnityEngine;
using System.Collections;

public class Positioning : MonoBehaviour {
	
	public Vector3 localPosition;
	public Quaternion localRotation;
	
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	public void PositionGun(){
		transform.localRotation = Quaternion.identity;
		transform.localPosition = localPosition;
		transform.localRotation = localRotation;
	}
}

Usually that’s not the way to do the job: create an empty object, child it to the player and adjust its position and rotation. When you want to add the weapon, child it to the empty object and reset its local position/rotation: it will be exactly at the same position/rotation as the empty object, and both will follow the player wherever it goes:

using UnityEngine;
using System.Collections;
 
public class Positioning : MonoBehaviour {
 
    public Transform weaponPlace; // drag the empty object here
 
    public void PositionGun(){
       transform.parent = weaponPlace; // child the gun to the empty object
       transform.localRotation = Quaternion.identity; // reset local rotation...
       transform.localPosition = Vector3.zero; // and local position
    }
}