Player Spins While Looking At Mouse

I have a pretty simple script that makes the player look at the mouse

-- char is the player's character
local lookAt = Vector3.new(mouse.Hit.Position.X,char.PrimaryPart.Position.Y,mouse.Hit.Position.Z)
char.PrimaryPart.CFrame = CFrame.new(char.PrimaryPart.Position,lookAt)

Image from Gyazo
The issue is that when the player looks at the floor right next to the character, the character starts wildly spinning

how do i fix this?

If this problem is related to having ShiftLock enabled then if possible I suggest you disable it.

1 Like

this works fine for me in new studio default camera settings

do you have any custom cam settings or are you not filtering the character it maybe targeting this character with the mouse hit

seems it might all be caused by the mouselock your using

Set the Mouse’ TargetFilter = workspace

You could just use the humanoidrootpart’s upvector in a lookat constructor.

local hit = mouse.Hit.Position

local HumRoot = char.PrimaryPart
local HumCF = HumRoot.CFrame
local lookAt = Vector3.new(hit.X, HumCF.Position.Y, hit.Z)

HumRoot.CFrame = CFrame.lookAt(HumCF.Position, lookAt, HumCF.UpVector)