Motor6d Turret Won't Follow Mouse

Ok basically I want this thing to follow wherever the mouse moves (a turret on top), it’s a motor6d and honestly I’ve never done this before.

https://i.gyazo.com/59be615dd520550f697a65327c525c1c.mp4 This here shows the issue occuring

The script is:

	local Distance = (alfiebad.Position - Vector3.new(mouse.Hit.p)).magnitude
	local Difference = alfiebad.CFrame.Y - mouse.Y
		alfiebad.Joint.C0 = alfiebad.Joint.C0:lerp(alfiebad.Joint.C0 * CFrame.Angles(-(math.atan(Difference / Distance)), (((alfiebad.CFrame.p - mouse.Hit.p).Unit):Cross(mouse.Hit.p)).Y * 1, 0), 1.5 / 2)

Ignore variable names I didn’t set up most of them also no idea if this is an overcomplicated method or even if this is how you do it

Why are you doing all this?
Maybe for limits tho, ok so, try to o CFrame.new(pos,lookat(mouse.Hit.p))
an than clamp the result to make it fit your needs, hope this helps a bit

I think your problem is that when you type lets say;

RightArmWeld.C0 = RightArmWeld.C0

instead of like

RightArmWeld.C0 = CFrame.new(rightArmWeld.C0.p, GoalPosition)

you’re setting the weld to the current rotation it’s at + where your mouse is, instead of setting it to just where your mouse is. This would cause the script to rotate on its own, since you’re creating a turret that spins where the mouse is from what the code says.

What you’re doing currently is no different from rotating a block is what i’m saying. this is an example of how you rotate a block with a weld.

RightArmWeld.C0 = RightArmWeld.C0 * CFrame.Angles(math.rad(1),0,0)

Found solution did something similar to what Draco posted but opposite way round and that worked for some reason