First Person Weapon Bug

I am currently having issues with the weapon and arms of the player in first person, in third person it looks fine when a player looks up and down but in first person the weapon goes through the player’s camera

https://gyazo.com/8b323cf6c19339186a36c99a79b36ef9

I’ve tried everything but nothing seems to work.

game:GetService("RunService").RenderStepped:Connect(function()
    Character["Right Arm"].LocalTransparencyModifier = Character["Right Arm"].Transparency
    Character["Left Arm"].LocalTransparencyModifier = Character["Left Arm"].Transparency
    local camCF = camera.CoordinateFrame
    local distance = (Character.Head.Position - camCF.p).magnitude
    if Gun ~= nil and not Vars.FireStance and Humanoid.Health ~= 0 then
        local angleComponent = -math.asin((Mouse.Origin.Position - Mouse.Hit.Position).Unit.Y)

        rightShoulder.C0 = CFrame.new(script.O_RS.Value, script.XX_RS.Value, script.ZZ_RS.Value) * CFrame.Angles(angleComponent, script.X_RS.Value, 0)
        leftShoulder.C0 = CFrame.new(script.O_LS.Value, script.XX_LS.Value, script.ZZ_LS.Value) * CFrame.Angles(angleComponent, script.X_LS.Value, 0)
        toolGrip.C0 = CFrame.new(script.O.Value, script.XX.Value, script.ZZ.Value) * CFrame.Angles(angleComponent, script.Y.Value, script.Z.Value)
        neck.C0 = CFrame.new(0, 1, 0) * CFrame.Angles(angleComponent + 1.55, math.pi, 0)
    else
        rightShoulder.C0 = originalRightShoulderC0
        leftShoulder.C0 = originalLeftShoulderC0
        neck.C0 = originalNeckC0
        toolGrip.C0 = originalToolGripC0
    end
end)

This is because the shoulder joints of which you’re rotating are positioned at a offset from the camera’s position when in first person. Because of this and the way that you’re getting the angle and setting the rotations, the arms won’t be aligned with the camera.

Oh okay, how can I fix this code wise?

Developers typically use viewmodels for these sorta things (a non-replicated model with arms) that is used to improve the visual experience for the client. I can think of three options:

  1. Use a viewmodel that replaces the original character’s arms and gun when the client has entered first person
  2. Don’t use a viewmodel, but set the arms’ and gun’s CFrame relative to the camera when in first person and replicate this across the clients (might produce some funny visuals such as the gun partly being inside the character’s head etc.)
  3. Base the arms’ CFrames on the gun’s position using an inverse kinematics method to grab onto the gun and position the gun in a way so that the gun and arms look good in both 1pp and 3pp (person perspective).

How you do it is up to you and your skill level, these are all valid options.