How to make a part rotate so that it's always facing up?

I have a part that is placed inside of a generated gun that produces a loot beam. The gun is unanchored, so when it is generated it will fall over. Wondering how I would go about making it so that the loot beam is always pointed up, even when the gun has fallen over.

Loot beam on a gun that has fallen over:
image

Desired effect:
image

EDIT: Here is what the beam part looks like if that helps any
image

Tried looking at different topics on this but all of them seem to be about aiming the part at the player.

This is a shot in the dark but try putting the beam into an attachment inside the beamPart. I believe it can maintain its constant Y that way.

Not entirely sure on the best method of producing your desired effect. However, if you just want the part to look up, you could do something like this

Part.CFrame = CFrame.new(Part.Position, Part.Position + Vector3.new(0, 1, 0))

The Y-axis is always pointing up in world space (unless you change the world rotations), so you just have to tell the part to look at a point super high in the sky…

part.CFrame = CFrame.lookAt(part.Position, Vector3.new(0, 100000, 0))