How do I make a player's head move on the server side?

This is my script. It’s used on a local script. It works on client side but not the server side(Because it’s a local script) and I want to know how to make it work on the server side. If you know how to add it, please tell me! Thanks.

local camera = workspace.CurrentCamera

local char = game.Players.LocalPlayer.Character
local root = char:WaitForChild("HumanoidRootPart")
local Neck = char:FindFirstChild("Neck", true)
local YOffset = Neck.C0.Y

local CFNew, CFAng, asin = CFrame.new, CFrame.Angles, math.asin

game:GetService("RunService").RenderStepped:Connect(function()
	local CameraDirection = root.CFrame:ToObjectSpace(camera.CFrame).LookVector

	if Neck then
		Neck.C0 = CFNew(0, YOffset, 0) * CFrame.Angles(3 * math.pi/2, 0, math.pi) * CFAng(0, 0, -math.asin(CameraDirection.x)) * CFAng(-asin(CameraDirection.y), 0, 0)
	end
end)
1 Like

You would need to send the neck joint cframe to the server (or camera look vector and recalculate on the server) using remotes. The server would then need to run the same code as the client to set the neck joint cframe.

Why exactly do you need this on the server? Note that the client could potentially send anything to the server and cause any neck position at will.