Weird CFrame.lookAt() bug

Hello
I am experiencing a weird bug with CFrame.lookAt(). When I type this line of code:

char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, Vector3.new(aimatt.WorldPosition.X, aimatt.WorldPosition.Y, aimatt.WorldPosition.Z))

It works (but it rotates the character up which is not what I want)
However, when I type this out:

char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, Vector3.new(aimatt.WorldPosition.X, aimatt.WorldPosition.Y, 1))

Nothing happens; the character just stays in place and doesn’t rotate towards the attachment.
Thank you for your help in advance

1 Like

Judging off of your code, if you want your character to face aimatt.WorldPosition, here is what you could do:

local hPos = char.HumanoidRootPart.Position
local aPos = aimatt.WorldPosition
char.HumanoidRootPart.CFrame = CFrame.lookAt(hPos, Vector3.new(aPos.X, hPos.Y, aPos.Z))

Basically, this code will make the HumanoidRootPart face the target position on the X and Z axes (left/right, forward/back), and the HumanoidRootPart’s position on the Y axis, so that it does not face up or downwards towards the target.

Hopefully this helps. Let me know if you had any other questions!

1 Like