I'm trying to make a tank script that allows you to turn the turret & barrel with your mouse. The turret is a cylinder so it has to move left and right on the y axis. Yes, the y axis. Since the tank is unanchored I am using a weld to CFrame the turret.
I have an example of my tank script at my place. It can be driven. You can press f to fire the machine gun (which is my old script that I need to rewrite.) With all of the crazy things I have tried you'd see that I can't get the barrel to point at the mouse.
This is probably very inaccurate but it would be something similar to this I'm guessing? Just kind of an example of what I have tried.
wait(1)
player = game.Players.LocalPlayer
mouse = player:GetMouse()
weld = findCar.VehicleSeat.Connection -- this is the weld that I need to CFrame
while true do
wait()
weld.C0 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(mouse.Origin.z,0,0)
end
I really don't know how to ask this. And I don't really have too much information to give.
Summary of my question: Since the turret rotates left and right on the y axis. How do I make it turn left and right with your mouse by CFraming the weld.

4 comments
Please enclose your code in blocks so we can better understand it.
I think its mouse.hit.lookVector
Try CFrame.Angles(0, 0, mouse.Origin.z). (Angles is the same as fromEulerAnglesXYZ)
I tried lookVector just now, I seemed to be closer but apparently lookVector is a forward position. At least it would follow the mouse. So apparently if I used CFrame.Angles(mouse.Origin.z,0,0) or CFrame.Angles(0,0,mouse.Origin.z) then it spins around and doesn't point towards the mouse, if you move your camera then it spins wildly. Kind of hard to explain. I still haven't found a solution though.