Hi all, I am making a turret for my game and I want it to rotate towards the player it is attacking. I have a script that detects the closest player, so I just need a script to rotate the model towards the other model. And I also want the model to rotate in Y only
For the normal part I use a script like this:
RunService.Heartbeat:Connect(function()
local nearestPlayer, distance, direction = findNearestPlayer()
if nearestPlayer then
if distance <= 10 then
script.Parent.Parent.Rotation.CFrame = CFrame.lookAt(script.Parent.Parent.Rotation.Position, nearestPlayer.HumanoidRootPart.Position)
script.Parent.Parent.Rotation.Orientation = Vector3.new(0, script.Parent.Parent.Rotation.Orientation.Y+180, 0)
end
end
end)