How would I make a characters head follow the mouse in only on axis?

Hey there! I am trying to make a characters head follow the mouse in one axis, but I just can’t seem to do it. It has to be seen on the server.

Local script I used:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local character = script.Parent

local changeYEvent = script.Parent:WaitForChild("ChangeY")

game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
	changeYEvent:FireServer(mouse.Hit.p, mouse.Hit.p.Y)
end)

Server script I used:

local neck = script.Parent:WaitForChild("Torso"):WaitForChild("Neck")
local normalC0 = neck.C0
local head = script.Parent:WaitForChild("Head")
local torso = script.Parent:WaitForChild("Torso")

local changeYEvent = script.Parent:WaitForChild("ChangeY")

changeYEvent.OnServerEvent:Connect(function(player, pos, Y)
	local Distance = (head.CFrame.p - pos).magnitude
	local Difference = head.CFrame.Y - Y
	
	neck.C0 = normalC0 * CFrame.Angles(-(math.atan(Difference / Distance) * 0.5), (((head.Position - pos).Unit):Cross(torso.CFrame.LookVector)).Y * 1, 0)
end)

Any help is greatly appreciated!

1 Like
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local mouse = player:GetMouse()

mouse.Move:Connect(function()
	head.CFrame = CFrame.new(head.CFrame.X, mouse.Hit.Y, head.CFrame.Z)
end)

Movement of the player’s character model replicates to the server even when performed from a local script.

5 Likes

Hello! Try this!

local RunService = game:GetService("RunService")

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

local Camera = workspace.CurrentCamera

local Character = Player.Character or Player.CharacterAdded:Wait()
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

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 = PlayerMouse.Hit.p
				
				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

Put it in LocalCharacterScripts as a local script.

sir that there is a free model and has nothing to do with what he wants

4 Likes