How to make NPC rotate towards player on the Y axis

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)

Thanks for helping

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)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.