I made this script but I have no idea how to make the NPC rotate on the Y axis
local RunService = game:GetService('RunService')
RunService.RenderStepped:Connect(function()
local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
script.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position, Vector3.new(character.HumanoidRootPart.Position.X, character.HumanoidRootPart.Position.Y, character.HumanoidRootPart.Position.Z))
end)
If you want the NPC to only rotate on the y-axis, the position that the CFrame is “looking at” should have the same y-coordinate as the position of the CFrame. So you’ll just have to change one of the arguments given to the Vector3 constructor.
local RunService = game:GetService('RunService')
RunService.RenderStepped:Connect(function()
local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
script.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position, Vector3.new(character.HumanoidRootPart.Position.X, script.Parent.HumanoidRootPart.Position.Y, character.HumanoidRootPart.Position.Z))
end)