How to make torso/head follow camera? (Serversided)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’d like some help with making a script that makes the player’s torso and head look at the camera just like madcity for example.

  2. What is the issue? Include screenshots / videos if possible!
    I’ve tried many scripts but non of them are serversided

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I tried to make the script down below serversided but then it rotating weirdly.


local camera = workspace.CurrentCamera

local character = game.Players.LocalPlayer.Character
local root = character:WaitForChild("HumanoidRootPart")
local neck = character: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) * CFAng(0, -asin(cameraDirection.x), 0) * CFAng(asin(cameraDirection.y), 0, 0)
	end
end)
1 Like

I see what are you trying to do, so I’ve typed this script 6 months ago, I don’t know if it works or not, try it and tell me if it worked(Place the script in StarterCharacterScripts)

local RunService = game:GetService("RunService")
Local players = game:GetService("Players")
local Character = script.parent
local Player =  Players:GetPlayerFromCharacter(character)
local PlayerMouse = Player:GetMouse()

local Camera = workspace.CurrentCamera

local Head = Character:WaitForChild("Head")
local Neck = Head:WaitForChild("Neck")

local Torso = Character:WaitForChild("UpperTorso")
local Waist = Torso:WaitForChild("Waist")

local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local NeckOriginC0 = Neck.C0
local WaistOriginC0 = Waist.C0

Neck.MaxVelocity = 1/3

function getPoint()
	local r=Camera:ViewportPointToRay(PlayerMouse.X,PlayerMouse.Y,1337);
	return r.Origin+r.Direction;
end;

RunService.RenderStepped:Connect(function() 
	local CameraCFrame = Camera.CoordinateFrame

	if Character:FindFirstChild("UpperTorso") and Character:FindFirstChild("Head") then
		local TorsoLookVector = Torso.CFrame.lookVector
		local HeadPosition = Head.CFrame.p

		if Neck and Waist then
			if Camera.CameraSubject:IsDescendantOf(Character) or Camera.CameraSubject:IsDescendantOf(Player) then
				local Point = getPoint();

				local Distance = (Head.CFrame.p - Point).magnitude
				local Difference = Head.CFrame.Y - Point.Y

				Neck.C0 = Neck.C0:lerp(NeckOriginC0 * CFrame.Angles(-(math.atan(Difference / Distance) * 0.5), (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 1, 0), 0.5 / 2)
				Waist.C0 = Waist.C0:lerp(WaistOriginC0 * CFrame.Angles(-(math.atan(Difference / Distance) * 0.5), (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 0.5, 0), 0.5 / 2)
			end
		end
	end	
end)
1 Like

You will need part of that system client sided, cause theres no other way to get the camera facing of the client on server side.

So, mandatory to read the camera client side, if the torso/head Motor6D updating doesnt replicate to server, then, fire a remote from client, sending the current camera rotation to server script to apply the motor6d update…

I think I never tried, but, I think the motor6D update from client would replicate to server due to ownership… otherwise, firing a remote loop on a RunService step to tell a server script to update the motors doesnt sound like a good idea… I think on client side is the best approach and replicates, theres no need to do it server side if its only cosmetic