local event = script.Parent.Rotate
local mesh = script.Parent.MeshPart
local function getCFrame(position, lookAt)
local lookVector = (position - lookAt).Unit
local modelUpVector = Vector3.new(0, 1, 0)
local rightVector = lookVector:Cross(modelUpVector)
local upVector = rightVector:Cross(lookVector)
return CFrame.fromMatrix(position, rightVector, upVector)
end
event.OnServerEvent:Connect(function(plr, pos)
print("Fired")
mesh.CFrame = getCFrame(mesh.Position, -pos)
end)
If the turret’s FrontFace is the face which you want to turn towards the mouse, you can just use CFrame.new(position, lookAt) constructor to make it look there.