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
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)