I have two parts that are held together by a weld. They're called TurretSwivel and Turret. Turret is the part that moves. I need to CFrame the weld by using something similar to the code below.
This is an example of what I have tried:
wait(1)
player = game.Players.LocalPlayer
mouse = player:GetMouse()
findCar = game.Workspace:FindFirstChild("Car"..player.Name)
if findCar then
mainGun = findCar.Barrel
weld = findCar.VehicleSeat.Weld
mouse.Move:connect(function()
local torsoPos = findCar.TurretSwivel.Position
local dir = (mouse.Hit.p - torsoPos).unit
weld.C0 = CFrame.new(0,0,0) * CFrame.Angles(-math.atan2(dir.X,dir.Z) + math.pi/2, 0, 0)
end)
end
When I use this script, it works at first but soon the turret stops aiming at the mouse.
Please help answer this, thanks. And if you have any questions please ask.
