I'm trying to make a script where an r15 NPC turns their entire body to look at the player, but they can only turn their body if they aren't already moving.
The NPC is supposed to go on a patrol, and when it stops at certain corners, it can face the player. It would also be good if the NPC went back to it's original rotation if the player is out of the range, like if the NPC was facing forward at the wall. It would go back after the player has left.
I have the body gyro but the aiming script I try don't seem to work, they always just face towards the side and don't seem to look at me.
this is the aiming script i have
function findTorso(pos) local torso = nil local dist = 1000 local child = workspace:children() for i=1, #child do if child[i].className == "Model" then local h = child[i]:findFirstChild("Humanoid") if h ~= nil then local check = child[i]:findFirstChild("Torso") if check ~= nil then if (check.Position - pos).magnitude < dist then torso = check dist = (check.Position - pos).magnitude end end end end end return torso end while true do wait() local torso = findTorso(script.Parent.Position) if torso ~= nil then script.Parent.CFrame = CFrame.new(script.Parent.Position, torso.Position) end end
and the gyro is set to 0,inf,0