can you guys help me make the characters head look at the mouse pointer. i made that the whole character looks at the mouse pointer but i only want the head to look
this is the code i made
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local Root = player.Character.HumanoidRootPart
while true do
wait()
local RootPos, MousePos = Root.Position, mouse.Hit.Position
Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
end
this is the full code to the local script
i have a script that just plays a tween with the given cframe
local Plr = game.Players.LocalPlayer
local neck = Plr.Character:WaitForChild("Torso"):WaitForChild("Neck")
local camera = workspace.CurrentCamera
--local hip = Plr.Character.Torso:WaitForChild("Right Hip")
local humanoid = Plr.Character.Humanoid
local theplace = nil
while wait(.075) do
local mouse = Plr:GetMouse()
theplace = Plr.Character.Torso.CFrame:toObjectSpace(camera.CFrame).lookVector
local value1 = CFrame.new(0,1.025,0) * CFrame.Angles(math.tan (theplace.Y)+math.rad(-90),0,math.acos (theplace.X)+math.rad(90))
if humanoid.Health == 0 then
value1 =CFrame.new(0,1.025,0) * CFrame.Angles(math.rad(0),0,math.rad(90))
game.ReplicatedStorage.HeadLook:FireServer(value1)
else
if script.Parent.Running.Value == false then
--theplace = Plr.Character.Torso.CFrame:toObjectSpace(mouse.Hit).lookVector
--this is what you need
theplace = Plr.Character.HumanoidRootPart.CFrame:toObjectSpace(camera.CFrame).lookVector
value1 = CFrame.new(0,1.025,0) * CFrame.Angles(math.tan (theplace.Y)+math.rad(-90),0,math.acos (theplace.X)+math.rad(90))
else
theplace = Plr.Character.HumanoidRootPart.CFrame:toObjectSpace(camera.CFrame).lookVector
value1 = CFrame.new(0,1.025,0) * CFrame.Angles(math.asin (theplace.Y)+math.rad(-90),0,math.acos (theplace.X)+math.rad(90))
end
local value = CFrame.Angles(-math.asin(theplace.Y)+5,0,math.asin(theplace.X)+84.75)
--print(value1)
--84.75
--neck.C0 = value1
game.ReplicatedStorage.HeadLook:FireServer(value1)
end
end
Assuming you just want the character’s head to rotate around the Y-axis. The following is compatible with both avatar types.
do
local Game = game
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid")
local RigType = Humanoid.RigType.Name
local Limb = if RigType == "R6" then Character:FindFirstChild("Torso") or Character:WaitForChild("Torso") elseif RigType == "R15" then Character:FindFirstChild("Head") or Character:WaitForChild("Head") else nil
if not Limb then return end
local Joint = Limb:FindFirstChild("Neck") or Limb:WaitForChild("Neck")
local function OnRenderStep()
Joint.C0 = CFrame.lookAt(Joint.C0.Position, Vector3.new(Mouse.Hit.Position.X, Joint.C0.Position.Y, Mouse.Hit.Position.Z)) * if RigType == "R6" then CFrame.Angles(math.pi / 2, math.pi, 0) else CFrame.Angles(0, 0, 0)
end
RunService.RenderStepped:Connect(OnRenderStep)
end
do
local Game = game
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid")
local RigType = Humanoid.RigType.Name
local Limb = if RigType == "R6" then Character:FindFirstChild("Torso") or Character:WaitForChild("Torso") elseif RigType == "R15" then Character:FindFirstChild("Head") or Character:WaitForChild("Head") else nil
if not Limb then return end
local Joint = Limb:FindFirstChild("Neck") or Limb:WaitForChild("Neck")
local function OnRenderStep()
Joint.C0 = CFrame.lookAt(Joint.C0.Position, Vector3.new(Mouse.Hit.Position.X, Joint.C0.Position.Y, math.min(-Joint.C0.LookVector.Z, Mouse.Hit.Position.Z))) * if RigType == "R6" then CFrame.Angles(math.pi / 2, math.pi, 0) else CFrame.Angles(0, 0, 0)
end
RunService.RenderStepped:Connect(OnRenderStep)
end