Trying to make tank turret rotate with mouse

Hello. I am trying to get my turret to rotate to wherever the players mouse is pointing. I’ve tried achieving it and sorta worked but sorta not.

Explorer:
image

Basically the script below technically works but it rotates the whole tank due to welds. Now at the start of the game the tank is welded in the Framework script to keep the tank from falling apart. But i’m guessing that these welds are making it so the whole tank is rotated when i move my mouse.

LocalScript (Tank.LocalScript)

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

local TurretUnion = game.Workspace.M4Sherman.BodyKit.Turret.PrimaryPart

while wait() do
	TurretUnion.CFrame = CFrame.new(TurretUnion.Position, mouse.Hit.Position)
end

It’s hard to explain so here is a video of my problem.
robloxapp-20250119-0204318.wmv (1.3 MB)

And dw about the script inside the tool it doesnt do anything yet.

Any help is appreciated :smile:

You need to do this in the vehicle’s space. Something like:

local vehicleSpacePoint = Tank.Chassis.CFrame:PointToObjectSpace(mouse.Hit.Position)
TurretUnion.CFrame = CFrame.new(TurretUnion.Position, vehicleSpacePoint)

Also you need to set this CFrame on something like a RigidConstraint, not the CFrame of the turret itself, which will move everything else.

I’m sorry Im not quite sure i understand :sweat_smile: When you put Tank.Chassis what do you mean?

Let me send the full explorer:


Contents of seat is the same as shown in the original post :smile:

You can use the seat if it’s facing forward.

Huh
Im sorry i dont understand what you want me to do. Can you give a guide on what I do to make it work. Sorry im a bit of an amateur :sweat_smile: