local Players = game:GetService('Players')
local Scripts = script.Parent
local Configurations = Scripts.Parent
local Dummy = Configurations.Parent
local HumanoidRootPart = Dummy.PrimaryPart
local Torso = Dummy:WaitForChild('Torso')
local Head = Dummy:WaitForChild('Head')
local Neck = Torso.Neck
local Player = Players.LocalPlayer
local Character = Player.Character
while wait() do
local headPos = Head.Position
local lv = Torso.CFrame.LookVector
local dist = (headPos-Character.Torso.Position).Magnitude
local diff = headPos.Y-Character.Torso.Position.Y
Neck.C0 = Neck.C0 * CFrame.Angles(-(math.atan(diff/dist)), -(((headPos- Character.Torso.Position).Unit):Cross(lv)).Y, 0)
end
This code does not work, and there are no errors in OutPut
Can you explain what you are trying to achieve? You have provided almost to no information on the issue and you can not expect us to help you solve it.
I want to make the Npc turn its head to the position where the player is. There are no errors in OutPut, but the script itself doesn’t work for some reason
You could do this, and place it inside of the rig’s head:
local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
while task.wait() do
script.Parent.CFrame = CFrame.lookAt(script.Parent.Position, player.Character.Head.Position)
end
local Neck = -- Neck
local NeckC0 = Neck.C0
local function MoveHead()
local headPosition = -- npc head position
local playerPosition = -- players position
local X,Y,_ = CFrame.new(headPosition,playerPosition)
Neck.C0 = NeckC0 * CFrame.Angles(0,Y,0) * CFrame.Angles(X,0,0) -- Not joining them because of how CFrames work. If you do not want up and down movement remove the CFrame.Angles(X,0,0) part.
end