Character rotation issue

when the mouse changes its position the player is supposed to be looking at the mouse but instead got this weird behavior

here is the code btw:

local character = script.Parent.Parent
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local RunService = game:GetService("RunService")
local HumanoidRootPart = character.HumanoidRootPart

RunService.RenderStepped:Connect(function()
	local Rotation = CFrame.new(math.rad(Mouse.X), HumanoidRootPart.CFrame.Y, HumanoidRootPart.CFrame.Z)
	
	HumanoidRootPart.CFrame = Rotation
end)
1 Like

any clues on how to fix it cant stay like this forever

1 Like

For the Player icon duplicate the grey thing adduicorner in it with making size 1 and player icon’s size 1,0,1,0 it will be better

Try using while loop , Mouse.hit.position and vector3 . Make it that when the player moves the cursor the character’s rotates to cursor’s x y z .

almost got it right but it spins like crazy like wth

local character = script.Parent.Parent
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local RunService = game:GetService("RunService")
local HumanoidRootPart = character.HumanoidRootPart

RunService.RenderStepped:Connect(function()
	-- lets try lol
	local mousePos = Mouse.Hit.Position
	
	HumanoidRootPart.CFrame = HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(mousePos.Y), 0)
end)

i need it please help me i am struggling to fix this issue

I’m not much of a scripter but i think you should try putting :Wait() at RenderStepped

The latest code you provided in this thread is adding rotation to the current CFrame of the HumanoidRootPart, so then that means it’s rotating continously.
The workaround to this is to only get the position, and add rotation to that.

HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position) * CFrame.Angles(0, math.rad(mousePos.X), 0)

You may also want the character to point at where the cursor is pointing at? The code above only sets the rotation to where the cursor is in the X axis in the workspace. Which will cause really weird behavior.
Use this instead.
In this code the CFrame has 2 arguments in it. The first one is the origin, and the other is lookAt, so the CFrame calculates where to point at. You may not want to apply any other orientations other than Y because some weird behavior happens such as character rotating downwards/upwards.

-- Get the euler angles, Y is the only one needed.
local rx, ry, rz = CFrame.new(HumanoidRootPart.Position, mousePos):ToEulerAnglesYXZ()
-- Remember that this returns radians, so you have to use math.deg to convert it to degrees.
-- But since CFrame.Angles uses radians, there is no need for conversion.
-- Apply CFrame to the HumanoidRootPart
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position) * CFrame.Angles(0, ry, 0)

A :Wait() is not needed in a RenderStepped event, this event fires when each frame has “stepped”.

2 Likes