What do you want to achieve?
I would like to make an R6 npcs head follow a player
What is the issue?
On R15 the script works fine but on R6 the npc looks down as if its head is broken
What solutions have you tried so far?
I changed some of the numbers on the script but they would make the head tilt sideways
local char = script.Parent
local head = char:WaitForChild("Head")
local hrp = char:WaitForChild("HumanoidRootPart")
local neck = char:WaitForChild('Torso'):WaitForChild('Neck')
local xOffSet = neck.C0.X
local yOffSet = neck.C0.Y
local zOffSet = neck.C0.Z
local function getClosestPlayerHrp(dist)
local closestHrp = nil
for i, v in pairs(game.Players:GetChildren()) do
local tmpChar = v.Character or v.CharacterAdded:Wait()
local tmpHrp = tmpChar:FindFirstChild("HumanoidRootPart")
local tmpDist = (tmpHrp.Position - hrp.Position).Magnitude
if tmpHrp and tmpDist < dist then
closestHrp = tmpHrp
dist = tmpDist
end
end
return closestHrp, dist
end
while wait() do
local closestHrp, dist = getClosestPlayerHrp(20)
if closestHrp then
local dir = (closestHrp.Position - hrp.Position).Unit
local vecA = Vector2.new(hrp.CFrame.LookVector.X, hrp.CFrame.LookVector.Z)
local vecB = Vector2.new(dir.X, dir.Z)
local dotValue = vecA:Dot(vecB)
local crossValue = vecA:Cross(vecB)
local ht = hrp.Position.Y - closestHrp.Position.Y
local upAngle = math.atan(ht/dist)
local angle = math.atan2(crossValue, dotValue)
neck.C0 = CFrame.new(xOffSet, yOffSet, zOffSet)*CFrame.Angles(0, -angle, 0) * CFrame.Angles(-upAngle, 0, 0)
end
end