Scripting a tank turret to rotate according to mouse

The title is pretty self-explanatory, I want to make a turret of a tank (which is a model) rotate according to the mouse as smoothly as I can, I’ve tried multiple ways but none work.
How would I go about that?

1 Like
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local part = --Part that should rotate
part.CFrame = part.CFrame * CFrame.Angles(math.asin((mouse.Hit.Position - mouse.Origin.Position).Unit.Y), 0, 0)

Edit: Updated Script

small note: make sure you’re using .Position instead of .p and .Unit instead of .unit, since those are deprecated properties

2 Likes