Motor6D tool move with camera in first person

I am scripting a gun system that uses Motor6D’s. I have issues making the gun move relative to the camera when you are looking up and down in first person. (The game is going to be first person, so there is no need for if checks if you are in first person).

I have tried by changing Motor6D’s C1 position and orientation based off the camera’s CFrame. But eventually I just ran out of ideas and don’t know how to do this. Here’s what I tried:

game:GetService("RunService").Stepped:Connect(function()
	local pos = camera.CFrame
	local cfX, cfY, cfZ = pos:ToEulerAnglesXYZ()
	
	cfX *= 0.5
	
	if cfX * -1 > 1.22 then
		cfX = -1.22
	elseif cfX * -1 < -1.22 then
		cfX = 1.22
	end
	
	print(cfX)
	
	if player.Character.Humanoid.Health > 0 then
		local motor6D = player.Character.Torso:FindFirstChild("handle")
		
		motor6D.C1 = CFrame.Angles(math.rad(0), math.rad(0), cfX * -1) * CFrame.new(0, cfX * -RS.Configuration.TestMultiplier:GetAttribute("Num"), 0)
		
		player.Character["Right Arm"].CFrame = player.Character["Right Arm"].CFrame:ToObjectSpace(pos) * CFrame.new(-1, -1, -1)
		player.Character["Left Arm"].CFrame = player.Character["Left Arm"].CFrame:ToObjectSpace(pos) * CFrame.new(-1, -1, -1)
	end
end)

I don’t know how to do this. I would really appreciate any help, whether it is feedback on how to do this, or if it is a script. C1 is the gun, C0 is the torso.

Are you scripting viewmodels, or are you scripting a system in which you can see your whole body?

If you’re scripting viewmodels**… why?** You can just use the model’s pivot… (move the viewmodel’s primary part to the position of the camera)
If you’re scripting a system in which you can see your whole body, you should weld the gun to the right arm and just orientate the right arm.
You can also animate the gun by itself if you want to. Use a rig editor. Also pretty please just use C0… always.

What I want is when a different player looks at you, he will be able to see where you are actually pointing at, aswell as when you are in first person, you can actually see where the gun is pointing at. (and be able to move it up & down).
No, I am not going to weld the tool to the right arm because then it’s impossible to animate it.
What’s the difference between C1 and C0 though?

You should probably make a bone instead. Idk what I was thinking when I said you should weld it.
Also you know what? Using C1 is fine. I probably said that because I only use C0 to be consistent.

Changing the arm’s rx is a good idea, since that’s how I implemented it too, but please don’t change the arms’ CFrames to achieve this.

Change the arms’ bones’ CFrames. You should make some UnreliableRemoteEvents to transmit the camera orientation data, and make the client tween the Motor6D’s , since Motor6D’s CFrame’s are not replicated.

It’s simple really, but what you were doing was not the right way to do it. My solution also allows for animations to be played (including reloads and stuff!). You can rig all of this by putting the gun inside a character model, and then rigging, since the gun’s model will be inside the character when it’s taken out.

Hope I helped out!

Wait I’m kind of confused what to do here.
From what I understand, you want me to replace the arms with bones, and then change the bone’s CFrame to make the arms move, aswell as motor6D’s. This is all going to be done on the client.

Did I get it right? If not, can you explain step by step? Sorry if I am making this difficult.
I also have an issue with doing the CFrame math. I just can’t get it right.

Modify the Motor6D’s that connect the arms to the torso. It will not replicate, so you’ll have to use remote events to send the orientation info to other clients.

Okay. How do I do the CFrame math though. And it still needs to make the tool move with the arms while still preserving the animation.

im assuming you are moving the arm upa and down, and seeing the gun shifting in position. thats due to the pivot of the camera and arm being different, making any rotation shift the relative positions.

what youll need is to keep the offset between the right shoulder and the camera. what part are you using to animate the camera? (head or cam part)