Rotating Player in the direction of the camera

I want to rotate the player in the direction of their camera.

Kind of like this video:

So far I found a way to do it but it’s very hacky and only works on the server. I’m trying to create my dodge system on the client to reduce the load of the server. So if anyone has a way to do it please help.

Code so far:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local camera = game.Workspace.CurrentCamera
---The portion regarding changing the cframe will happen when you press a certain key
---As of right now it is just as it is
hrp.CFrame = CFrame.new(hrp.Position, Vector3.new(Camera.CFrame.Lookvector.X * 9999, hrp.Position.Y, Camera.CFrame.Lookvector.Z * 9999))
3 Likes

The code you shown only works on the client. What do you mean by how to make the system work on the client?

No the code I showed doesn’t work on client. If you were to change it to the server it would work.

It works on the server like this:

local remote = game.ReplicatedStorage:WaitForChild("Remote")

remote.OnServerEvent:Connect(function (plr, LookVector, Position)

local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")

hrp.CFrame = CFrame.new(hrp.Position, Vector3.new(LookVector.X * 9999, hrp.Position.Y, LookVector.Z * 9999))

end)

But if you did it on the client it wouldn’t.

1 Like

Get the camera’s CFrame, get the orientation with CFrame:ToOrientation(), then you should be able to get the Y rotation from it. After that, simply rotate the HumanoidRootPart as needed.