Turret DOESN'T work

I checked everything but for some reason it doesn’t work helppp
No errors in the output

I have 2 scripts - 1 local script in the starterplayerscripts and 1 script in the model
image
image
local script:

game:GetService("RunService").Heartbeat:Connect(function()
	local tank = game.Workspace:WaitForChild("tank")
	local gun = tank:WaitForChild("gun")
	local mouse = game.Players.LocalPlayer:GetMouse()
	local function getServoAngle(hinge, targetPosition)
		local baseAttachment = hinge.Attachment0
		local object_horizontal_offset = (baseAttachment.WorldCFrame):PointToObjectSpace(targetPosition)
		local object_yaw_angle = math.atan2(object_horizontal_offset.Z, object_horizontal_offset.Y)
		object_yaw_angle = math.deg(object_yaw_angle)

		return object_yaw_angle
	end
	local hinge = gun:WaitForChild("Yaw")
	while hinge.Attachment0 == nil do
		task.wait()
	end
	gun.PrimaryPart.Anchored = true
	gun.PrimaryPart.Anchored = false
	hinge.TargetAngle = getServoAngle(hinge, mouse.Hit.Position)
end)

script:

local seat = script.Parent:FindFirstChild("Seat",true)

print("seat:",seat)
if seat then
	seat:GetPropertyChangedSignal("Occupant"):Connect(function()
		if seat.Occupant then
			local player = game.Players:GetPlayerFromCharacter(seat.Occupant.Parent)
			if player then
				script.Parent.PrimaryPart:SetNetworkOwner(player)
			else
				script.Parent.PrimaryPart:SetNetworkOwner(nil)
			end
		else
			script.Parent.PrimaryPart:SetNetworkOwner(nil)
		end
	end)
end

If you need the model, here:
modeltest112.rbxm (10.6 KB)

1 Like

You forgot to set the hinge constraint to servo mode thats pretty much it.

image

1 Like

I changed actuatortype to “Servo” but i still can’t move the turret with my mouse

1 Like

Oh yeah also make sure the angular speed is more than 0 and everything is unanchored.

2 Likes

Thanks, i changed the angular speed and it helped)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.