✓ Accepted answer
Roblox has an example just for that on the wiki if you look at CFrame.fromMatrix
function lookAt(target, eye)
local forwardVector = (eye - target).Unit
local upVector = Vector3.new(0, 1, 0)
local rightVector = forwardVector:Cross(upVector)
local upVector2 = rightVector:Cross(forwardVector)
return CFrame.fromMatrix(eye, rightVector, upVector2)
end
Make sure target is the target objects position and the eye is the the turret's LookVector, also make sure this is all done on the server and not the client.
So for example I would call that function like this:
ObjectA.CFrame = lookAt(ObjectB.Position, ObjectA.CFrame.LookVector)
Make sure to substitute ObjectA and ObjectB with your actual objects.