-
I want to make the NPC look towards the player when the function is fired.
-
It is not working and it is making the NPC teleport.
Here is a gyazo that shows the problem in action.
https://gyazo.com/2b788267f4b5c217a3d4ade4366f2dda
local npcPosition = hit.Parent.HumanoidRootPart.Position
local targetPosition = lavaGolem.Torso.Position
lavaGolem.Torso.CFrame = CFrame.lookAt(npcPosition, Vector3.new(targetPosition.X, npcPosition.Y, targetPosition.Z))
It might be useful to have more code.
local npcPosition = hit.Parent.HumanoidRootPart.Position
local targetPosition = lavaGolem.Torso.Position
lavaGolem.Torso.CFrame = CFrame.lookAt(npcPosition, Vector3.new(targetPosition.X, npcPosition.Y, targetPosition.Z))
First, set your lavaGolem’s PrimaryPart/HumanoidRootPart’s CFrame instead of the Torso’s. You also have your variable’s mixed up (the targetPosition is the npcPosition and vice versa).
Here is some corrected code:
local targetPosition = hit.Parent.HumanoidRootPart.Position
local npcPosition = lavaGolem.Torso.Position
lavaGolem.Torso.CFrame = CFrame.lookAt(npcPosition, Vector3.new(targetPosition.X, npcPosition.Y, targetPosition.Z))
(Note it won’t work if the lavaGolem doesn’t have a HRP)
1 Like
The torso is the PrimaryPart. I don’t feel like adding a humanoidrootpart since I will need to change all the constraints and its quite a pain.
1 Like
Oh okay. I’ll edit that.
1 Like
I am currently testing and seeing some improvemet! I think it might work!
1 Like
Its working!! Thank you very much for the help! 
1 Like