How to make a tank with rotating turret?

Hello, i want to have a tank with rotating turret. I tried couple solutions but it didn’t help me.

The solutions i tried:

  1. I tried with hinge and it did work pretty well. Until I rode the tank. It did not attach properly to the tank and when I tried to rotate the turret while driving, the turret just popped off.

  2. I tried with weld and when i tried to rotate turret, all the parts of tank rotated too

  3. I tried with c0 of weld and when i tried to rotate it, the turret got inside the tank main body as shown in the image

The scripts are:

  1. Inside tank script:
event = game.ReplicatedStorage.d
kule = script.Parent.Taret.Kule

event.OnServerEvent:Connect(function(p, m)
	local _, rY, _ = CFrame.new(kule.CFrame.p, m):ToOrientation()
	local rX, _, rZ = kule.CFrame:ToOrientation()
	kule.CFrame = CFrame.new(kule.CFrame.p) * CFrame.fromOrientation(rX, rY, rZ)
end)
  1. Inside player script:
p = game.Players.LocalPlayer
mouse = p:GetMouse()
event = game.ReplicatedStorage.d

mouse.Button1Down:Connect(function()
	event:FireServer(mouse.Hit.Position)
end)

There’s a CFrame function you can use for BodyGyros. Maybe try using that to turn the Turret, making the YRotation = 0

All body movers got deprecate.

I tried it with AlignOrientation but nothing changes. It is rotating all tank. I just need to know how to rotate welded parts freely from each other.

I fixed it and I will explain how I fixed it. When I used c0 of weld, i forgot * in equality. For example I made weld.C0 = CFrame.fromOrientation(0, 90, 0) and it worked but it changed the offset too and my turret got inside the tank. So you need to put * to equality like this to change angle:
weld.C0 *= CFrame.fromOrientation(0, 90, 0)

1 Like