currently i only have this function, it works fine but it only tweens the whole npc. i want only for it to be the head
script.CFrame.Value = model.HumanoidRootPart.CFrame
local function lookAtPlayer(target)
local connection
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(
script.CFrame,
tweenInfo,
{Value = CFrame.new(model.PrimaryPart.Position, Vector3.new(target.Position.X, model.PrimaryPart.Position.Y, target.Position.Z))}
)
tween:Play()
connection = RunService.Stepped:Connect(function()
local old = script.CFrame.Value
model.PrimaryPart.CFrame = CFrame.new(model.PrimaryPart.CFrame.Position) * old - old.Position
tween.Completed:Connect(function()
connection:Disconnect()
end)
end)
end
if you want to use motor6d to help me achieve this, here is the neck motor
Just replace each mention of the “HumanoidRootPart” instance with the “Head” instance if you only want to manipulate the head of the NPC’s character model.
script.CFrame.Value = model.Head.CFrame
local function lookAtPlayer(target)
local connection
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(
script.CFrame,
tweenInfo,
{Value = CFrame.new(model.Head.Position, Vector3.new(target.Position.X, model.Head.Position.Y, target.Position.Z))}
)
tween:Play()
connection = RunService.Stepped:Connect(function()
local old = script.CFrame.Value
model.Head.CFrame = CFrame.new(model.Head.CFrame.Position) * old - old.Position
tween.Completed:Connect(function()
connection:Disconnect()
end)
end)
end