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

How to make player's head face mouse? (R15)

game:GetService("RunService").RenderStepped:Connect(function()
    local Target = Mouse.Hit
    local RotationOffset = (figure.PrimaryPart.CFrame - figure.PrimaryPart.CFrame.Position):inverse()
    local RealPos = -(figure.PrimaryPart.CFrame.p - Target.Position).Unit * 5000
    figure.Head.Neck.Transform = CFrame.new(Vector3.new(), RealPos) * RotationOffset
end)

My script doesn't seem too work, anyone have a working one.

1 answer

Well this script will make it so the player's head faces the mouse

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local cam = game.Workspace.CurrentCamera

repeat wait() until game.Workspace:FindFirstChild(player.Name) ~= nil

while true do
	local head = player.Character.Head
	head.CFrame = CFrame.new(head.Position, mouse.Hit.p*Vector3.new(1,0,1) + head.Position*Vector3.new(0, 1, 0))
	wait()
end

However, the player's body will move slightly while doing so. You can technically make them not move as much by setting the Head or HumanoidRootPart anchoring to true, but then the play will only rotate in place.

The wait part makes sure there is a character before the script runs (to prevent an error)

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