How do I make my player (R6) face towards my cursor (Y axis)

Try this. I Changed one thing in it

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

game:GetService(“RunService”).RenderStepped:Connect(function()
local Character = Player.Character
Character.HumanoidRootPart.CFrame = CFrame.new(Character.HumanoidRootPart.CFrame.Position, Vector3.new(Mouse.Hit.Position.X, Character.HumanoidRootPart.CFrame.Position.Y, Mouse.Hit.Position.Z))
end)

1 Like

i tried that my self, and i got the same result

1 Like

What is the animation supposed to be without the character following the mouse? (just a question)

1 Like

a jump and fall animation, which affects the character’s torso and head orientation. I also have a sprint animation too.

1 Like

That’s probably the issue (or at least part of it) , have you considered using Body-Gyros or any other body movers?

1 Like

No. I would much prefer a script that just turns the character (which is more reliable instead of using BodyMovers)

1 Like

hmmm…

Just for testing try putting the code in a while loop instead of using Runservice.RenderStepped, just to see how the character “reacts”

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

while true do
wait(.5)
local Character = Player.Character
Character.HumanoidRootPart.CFrame = CFrame.new(Character.HumanoidRootPart.CFrame.Position, Vector3.new(Mouse.Hit.Position.X, Character.HumanoidRootPart.CFrame.Position.Y, Mouse.Hit.Position.Z))
end

(Also i would recommend using heartbeat or stepped instead of render stepped, in this case)

This is how I’d personally do it:

RunService = game:GetService('RunService')
Players = game:GetService('Players')
Player = Players.LocalPlayer
Mouse = Player:GetMouse()
Char = Player.Character
if not Char then
	Player.CharacterAdded:Wait()
	Char = Player.Character
end

RootPart = Char:WaitForChild('HumanoidRootPart')

RunService.Stepped:connect(function()
	
	local MousePos = Mouse.Hit.p
	
	local lookToPosVector = Vector3.new(MousePos.X,RootPart.CFrame.Y,MousePos.Z)
	
	RootPart.CFrame = CFrame.new(RootPart.CFrame.p,lookToPosVector)
	
end)
12 Likes

Do you mind sharing how you fixed it? (some people that search this topic might like to know how it was solved)

Have a Great Day/Night!

1 Like

never mind about what i said before, it had a major issue which lagged out the game.

1 Like

This is exactly what i needed. Thanks!

1 Like

How would I make this turn slower?

You could consider tweening it.

There might be more efficient methods of tweening, but this is a simple method using Roblox’s TweenService

RunService = game:GetService('RunService')
TweenService = game:GetService("TweenService")
Players = game:GetService('Players')
Player = Players.LocalPlayer
Mouse = Player:GetMouse()
Char = Player.Character
if not Char then
	Player.CharacterAdded:Wait()
	Char = Player.Character
end

RootPart = Char:WaitForChild('HumanoidRootPart')

RunService.Stepped:connect(function()
	
	local MousePos = Mouse.Hit.p
	
	local lookVector = Vector3.new(MousePos.X,RootPart.CFrame.Y,MousePos.Z)
	
	--RootPart.CFrame = CFrame.new(RootPart.CFrame.p,lookVector)
	local goal = {}
	goal.CFrame = CFrame.new(RootPart.CFrame.p,lookVector)
 
	local tweenInfo = TweenInfo.new(1)
 
	local tween = TweenService:Create(RootPart, tweenInfo, goal)
 
	tween:Play()
	
end)


1 Like

What if I lerp it?

Player = Players.LocalPlayer
Mouse = Player:GetMouse()
Char = Player.Character
if not Char then
	Player.CharacterAdded:Wait()
	Char = Player.Character
end

RootPart = Char:WaitForChild('HumanoidRootPart')

local rs = game:GetService("RunService")
local speed = 8 -- change on how fast you want it to be

rs.Heartbeat:Connect(function(HB)
	
	local MousePos = Mouse.Hit.p
	
	local lookVector = Vector3.new(MousePos.X,RootPart.CFrame.Y,MousePos.Z)
	
	RootPart.CFrame = RootPart.CFrame:Lerp(CFrame.new(RootPart.CFrame.p,lookVector),HB * speed)
	
end)```

I don’t use lerp much, but from my understanding you’re supposed to feed it a percentage where 0 is the origin and 1 is the destination.

I think this is what you’re looking for:

RunService.Stepped:connect(function()
	
	local MousePos = Mouse.Hit.p
	
	local lookVector = Vector3.new(MousePos.X,RootPart.CFrame.Y,MousePos.Z)
	
	local target = CFrame.new(RootPart.CFrame.p,lookVector)
	
	RootPart.CFrame = RootPart.CFrame:lerp(target,.05)
	
end)

This code (in theory) gets you closer and closer to the desired CFrame by 5% each time.
It won’t actually technically reach the desired CFrame (in theory) but it’ll be so close that you can’t tell the difference.

Which method is better in your opinion?

Lerp is probably more efficient

TweenService is easier to understand, for future use

Thank you very much for spending your time answering my question.

And how would i make it 360 degrees? Including up and down?

It depends on what you want to go up and down. If you want the character’s head to look up and down, you can modify the C0 property of the Head’s Neck joint.