My MoveTo() script is not working!

My code is supposed to make an NPC follow the player, but instead the NPC walks in a circle around the player.


I want it to follow the player, that is all!

local char = nil

script.Parent.View.Touched:Connect(function(prt)
	local hum = prt.Parent:FindFirstChild("Humanoid") --Player's humanoid
	if hum then
		if char == nil then
			char = prt.Parent
		end
	end
end)
while wait() do
	if char ~= nil then
		script.Parent.Enemy:MoveTo(char.Torso.Position) --Enemy is the humanoid for the the NPC
		if char.Humanoid.Health <= 0 then
			print("dead")
			char = nil
		end
	end
end
local char = nil

script.Parent.View.Touched:Connect(function(prt)
    if prt.Parent:FindFirstChild("Humanoid") and char == nil then
	    char = prt.Parent
    end
end)
while wait() do
    if char ~= nil then
	    script.Parent.Enemy.Humanoid:MoveTo(char.HumanoidRootPart.Position)
	    if char.Humanoid.Health <= 0 then
		    print("dead")
		    char = nil
		end
    end
end

Thank you for trying to help, but it still does not work and the npc spins around the player. :frowning:

Does that red box around the player have CanCollide on?

No, it doesn’t have CanCollide on.