Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you make the head follow your mouse?

I tried it doesn't work, It only moves the head, Not the rotation, Please help My Code:

local Mouse = game.Players.LocalPlayer:GetMouse()
local Motor = script.Parent:WaitForChild("Torso"):WaitForChild("Neck")

while true do
	wait()
	Motor.C1 = CFrame.new(0, -0.5, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0) + Mouse.Hit.LookVector
end

1 answer

I think this should work, this is Code I found some time ago. It was originally written to rotate entire character so I changed it for only head, so I don't know how it will work

local player = game.Players.LocalPlayer

local UserInputService = game:GetService("UserInputService")

local mouse = player:GetMouse()
local character = player.Character or player.CharacterAdded:wait()

local Head= character:WaitForChild("Head")

character:WaitForChild("Humanoid").AutoRotate = false


local gyro = Instance.new("BodyGyro",Head)
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
gyro .MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
gyro .P = 10000
	
game:GetService("RunService"):BindToRenderStep(
	"Updategyro ",
	Enum.RenderPriority.Character.Value,
	function()
		
		gyro .CFrame =
		CFrame.Angles(
			0,
			math.atan2(
				Head.CFrame.X-mouse.Hit.X,
				Head.CFrame.Z-mouse.Hit.Z
			),
			0
		)
end)
	
game:GetService("RunService"):BindToRenderStep(
	"UpdateNeckC1",
	Enum.RenderPriority.Character.Value,
	function()
		character.UpperTorso.BodyFrontAttachment.CFrame =
		CFrame.new(0,-0.5,0,-1,0,0,0,0,1,0,1,-0)
		*CFrame.Angles(
			-math.atan2(
				character.UpperTorso.BodyFrontAttachment.CFrame.Position.Y-mouse.Hit.Y,
				math.sqrt((character.Head.CFrame.X-mouse.Hit.X)^2+(character.Head.CFrame.Z-mouse.Hit.Z)^2) --Distance formula
			),
			0,
			0
		)
end)

16 comments

0

It breaks.

0

what do you mean by that?

0

It does error lol

0

what does it say?

0

Workspace.FixRobloxz.LocalScript:6: bad argument #2 to '?' (Vector3 expected, got CFrame)

0

I changed it

0

It does worse. I need the head to look at the mouse.

0

Ok I'm changing everything I think I know how to fix this

0

I use motor6d bruh.

0

use My script

0

That Script? It doesnt work aaaaaaaaaaaaaaa

0

What do you mean by that?

0

then set desired angle of motor6d that CFrame.Angles( math.atan2( Head.CFrame.Y+mouse.Hit.Y, Head.CFrame.Z-mouse.Hit.Z )

0

I tried it before, I want it to look up and down

0

For just up and down, make Y and X axis 0

0

Nah, I already did it. :/

This discussion is preserved as it was. New answers, comments, and votes are closed.