So this script is supposed to be a npc following script as you can see it does not follow me it just stays still like nothing happened and no outputs either which makes it harder for me to tell what was done wrong

local torso = script.Parent.UpperTorso
local Humanoid = script.Parent.TestingDummy -- this is a humanoid
local SpawnCF = script.Parent.UpperTorso.CFrame

function findNearPlayer()
	for i,v in next,game.Players:GetPlayers() do
		if v.Character then
			local char = v.Character
			if char:FindFirstChild('Humanoid') and char:FindFirstChild('UpperTorso') then
				local Ptorso = char.UpperTorso
				if (Ptorso.Position - torso.Position).magnitude <= 8900000 then
					return v




				end
			end
		end
	end
return nil
end


while wait() do
	local player = findNearPlayer()
	if player ~= nil then
		Humanoid:MoveTo(player.Character.UpperTorso.Position)
	else
		Humanoid:MoveTo(SpawnCF.p)
	end
end

1 comment

0

The parameters of MoveTo() are location and part. You need to put a Vector3 position, and a part's position.You could also try :WalkToPoint(), if that's even a thing you can use in a script.