I'm making a script where when the player gets near the NPC, the NPC looks at the player. It works but I want it to ignore the Y and X axis.
script.Parent.Touched:connect(function(Char) local Humanoid = Char.Parent:FindFirstChild("Humanoid") if Humanoid ~= nil then local torso = Char.Parent:FindFirstChild("HumanoidRootPart") while wait() do script.Parent.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.Parent.HumanoidRootPart.Position, torso.Position) end end end)
How do I go about doing this?
I think what you are really asking is for is how to set the "look at" position so that it's the same height as the NPC's HumanoidRootPart. That way, we can "look at" a Position, while only taking into account its X and Z coordinates, and we won't topple over our NPC.
Here is your code with the above change, plus some clean-up
script.Parent.Touched:connect(function(Char) local Humanoid = Char.Parent:FindFirstChild("Humanoid") if Humanoid ~= nil then local torso = Char.Parent:FindFirstChild("HumanoidRootPart") local rotatingPart = script.Parent.Parent.HumanoidRootPart while wait() do local lookAt = Vector3.new( torso.Position.X, rotatingPart.Position.Y, torso.Position.Z ) rotatingPart.CFrame = CFrame.new(rotatingPart.Position, lookAt) end end end)