I recently wrote code that forces your character to look at your mouse. However, the problem is that if you move your mouse in a specific direction, your character will start floating in the air, with the legs not touching the ground.
Although this is easily understandable from the code I wrote, I am not sure how to fix it. I want both feet to remain firmly planted on the ground, with the mouse only affecting how the torso rotates left and right. This is more easily understandable with a simple test - just plop this code in a LocalScript in StarterGui and start moving the mouse around.
The following is a LocalScript inside StarterGui. No errors appear in the Output.
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local chr = plr.Character
local mouse = plr:GetMouse()
chr:WaitForChild("Humanoid").AutoRotate = false
mouse.Move:connect(function()
chr:WaitForChild("Torso").CFrame = CFrame.new(
chr.Torso.Position, --Position
mouse.Hit.p) --Look at
end)

2 comments
Why does using the direction work better than simply making you look toward the mouse directly, as I had it? Also why does multiplying the direction by 1,0,1 make it not affect y but if you put what I had before and multiply that by 1,0,1 it still works the same way, affecting y?
Responded to questions by editing answer.