CFrame.lookat freezing the player

Hey I’m a beginner and I need some help with something. I’m trying to make the players head follow the mouse. I used CFrame.lookat() but when I tested it out the player started having a seizure (shaking really fast) I also couldnt move. Heres the code:

--- In startercharacter scripts (server script)
script.Parent["lookAt()"].OnServerEvent:Connect(function(player, mousePOS)
	print(mousePOS)
	local head = script.Parent:WaitForChild("Head")
	head.CFrame = CFrame.lookAt(head.Position, Vector3.new(mousePOS))
end)
--- In startercharacter scripts (local Script)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

while true do
	wait(0.001)
	script.Parent["lookAt()"]:FireServer(mouse.Hit)
end

Then there’s a remote event in starter character scripts.
I feel like there’s a lot of improvements my codes needs anyways so help me out.

For the second script, instead of while true do, you can use renderstep or while task.wait(0.03) do.
Also the last time I used :LookAt() to make that lookat mouse effect, my character got flung into the abyss. I don’t know why it won’t move.
Pretty much all I understand about :LookAt()
sorry lol

1 Like

I believe the problem is because you’re setting the CFrame of the head directly, moving the body along with it. What you want to do is modify the neck’s motor6d’s cframe.

Guides exist on how to do this based on where your camera is looking, but simply substituting the camera.CFrame with your CFrame.lookAt(head.Position, Vector3.new(mousePOS)) in the guides should give you the result you’re looking for.