Rotate attached object in front of first person character

You need to figure out what axis you actually want to rotate around.
Then, transform the rotation to the basis of that axis, rotate, and transform back.
This requires some compound matrix math, and is why 3D linear algebra is actually important to game development!
I can’t write out the exact formula for you, because it depends on exactly how you’ve set up your scene graph.
However, I would assume that you want the camera as a reference. In that case, you can do the following:

  1. get world rotation of object
  2. get camera rotation
  3. invert camera rotation
  4. multiply world rotation by inverse camera rotation
  5. apply the rotate-around-X or whatever it is you want to do, camera relative
  6. multiply by the forward (non-inverse) rotation of the camera
  7. set as the world rotation of the object