MoveTo: is not working on the player(NPC)

Script:

local npc = script.Parent
local debounce = false

npc.Humanoid.Touched:Connect(function(hit)
	if hit and game.Players:GetPlayerFromCharacter(hit.Parent) then
		if debounce == false then
			debounce = true
			hit.Parent.Humanoid:TakeDamage(25) -- U SHOULD TO CHANGE THIS!!!
			wait(.25)
			debounce = false
			
			print("damaged")
		end
	end
end)


function FindPlayer(Position)
	local list = game.Workspace:GetChildren()
	local torso = nil
	local distance = 50 -- CHANGE THIS TOO
	local HRP = nil
	local humanoid = nil
	local player = nil
	
	for i = 1, #list do
		player = list[i]
		if (player.ClassName == "Model") and (player ~= script.Parent) then
			HRP = player:FindFirstChild("HumanoidRootPart")
			humanoid = player:FindFirstChild("Humanoid")
			
			if (HRP ~= nil) and (humanoid ~= nil) and (humanoid.Health > 0) then
				if (HRP.Position - Position).Magnitude < distance then
					torso = HRP
					distance = (HRP.Position - Position).Magnitude
				end
			end
		end
	end
	
	return torso
end

while true do
	wait(1)
	local target = FindPlayer(script.Parent.HumanoidRootPart.Position)
	if target ~= nil then
		script.Parent.Humanoid:MoveTo(target.Position, target)
		
		print(script.Parent.HumanoidRootPart.Position)
	end
end

So I made a regular npc that logically should follow me and hit me, but for some reason it does not move, although when I put the prints in the cycle, everything showed up

It also does damage, and it doesn’t give any errors.

Снимок экрана 2024-01-22 в 18.15.44
what am I doing wrong?

Make sure that there are no anchored parts inside of the NPC.

1 Like

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