How to move turret cannon up and down?

Make sure your model has a PrimaryPart set or else your pivot will not update automatically and behave correctly.

i want the green part to move

He is using PivotTo not SetPrimaryPartCFrame. You don’t need a Primary part to use PivotTo

Could you show the structure of the tank from Explorer? And what are you referring in the script as Turret?

grafik

The whole script currently, the Barrel is what i want to move

local RunService = game:GetService("RunService")
local Turret = script.Parent.Turret
local Hull = script.Parent.Hull
local Gun = Turret.Gun.Barrel

coroutine.resume(coroutine.create(function()
	RunService.Heartbeat:Connect(function()	
		if Turret:FindFirstChild("TurretSeat") then
			if Turret.TurretSeat.Steer == 1 then
				Turret:PivotTo(Turret:GetPivot() * CFrame.Angles(0, -math.rad(1), 0))
			elseif Turret.TurretSeat.Steer == -1 then
				Turret:PivotTo(Turret:GetPivot() * CFrame.Angles(0, math.rad(1), 0))
			end
			if Turret.TurretSeat.Throttle == 1 then
				Gun:PivotTo(Gun:GetPivot() * CFrame.Angles(-math.rad(1), 0, 0))
			elseif Turret.TurretSeat.Throttle == -1 then
				Gun:PivotTo(Gun:GetPivot() * CFrame.Angles(math.rad(1), 0, 0))
			end
		end
	end)	
end))

Yes he does, some other person ran into a problem similar to this one while using pivot, I was also not aware of it, here’s my post explaining it.

well i set the PrimaryPart but it still doesnt move

Told you.
Check the docs that pivotto is not related with PrimaryPart at all.

Also @Happygamer1983 you can use corountine.wrap which creates and starts a new thread. It’s much less text to write.

the turret movement doesnt work at all with coroutine.wrap()

That happens if you forget the brackets at the end. What I mean is:

coroutine.wrap(function()
end)()

Why are you using a coroutine? You’re just connecting an event.

I guess he wants to cause the script might be bigger.
Oh NVM ye @mniao is right. That’s an event why are you using coroutine?

Scripts still continue after connecting an event so that’s why I’m asking.

local runService = game:GetService("RunService")

runService.Heartbeat:Connect(function()
	print("heartbeat")
end)

print("do other stuff")

the coroutine is a left over from testing code, removed it

Well there is no need for it, have you checked if the Steer value is actually changing?

The problem is that he would need to rotate it by the small barrel before the actual gunpart and I am also facing that problem too in my games so I am not sure how I can help him.

it does change i, tested that earlier

i just need to rotate the barrel, i made it so the center point of the barrel is at the point where i want it to rotate

but how does the other rotate function work without .Value?

Steer is not a value it’s a property plus it is working the problem is at the throttle and is related to the positioning of the item.

@Happygamer1983 he thought that it’s a ObjectValue rather than a seat.

Since the Barrel is just a part you could try…
Barrel.CFrame *= CFrame.Angles(math.deg(10), 0,0)

2 Likes