Making npc look at me while it's playing an animation

I’m currently attempting to make a non-player character look at me while it’s playing an animation. I am succesfully able to make it happen when it’s idle as you can see here by running some random line of code I’ve intituively written.

Code in question :

while true do 
	workspace.d.Head.Neck.Transform = workspace.d.Head.Neck.Transform*workspace.d.Head.CFrame:ToObjectSpace(CFrame.new(workspace.d.Head.CFrame.Position,workspace.CurrentCamera.CFrame.Position)) wait() 
end 

Any recommendations/ideas in order to solve that? Also, I don’t have any knowledge in linear algebra yet, so if you could not be too much technical.

Suggestion; instead of using a while loop, use RunService.Heartbeat or RunService:BindToRenderStep instead.

2 Likes