My code is very simple, it finds nodes, walks to them, then detects for a player. Why isn't this working as well as it should and why is my soldier not moving right before it can detect a node? Here is the script to help you:

local work = game.Workspace
local soldier = script.Parent
local difficulty = work.DifficultyLevel.Value
local Humanoid = soldier.Humanoid
local Torso = soldier.Torso
local NodeIsReady = true
local Viewpoint = 100
local Node1 = work.Node1
local Node2 = work.Node2
print("load")
	function findNearestNode()
			for i,v in pairs(Node1:GetChildren()) do
			if (v.Position - Torso.Position).magnitude<Viewpoint then
				Humanoid:MoveTo(v.Position)
			end
			end
	end
	print("Function1 redy")
	function findNearestTorso(position)
   			NodeIsReady = false
	local torso = nil
	local dist = Viewpoint
	local temp = nil
	local human = nil
	local temp2 = nil
			local workstuff = work:children()
    			for x = 1, #workstuff do
				local persons = workstuff[x]
					if(persons.className=="Model") and(persons~= soldier) then
						local temp = persons:FindFirstChild("Left Arm")
						local human = persons:FindFirstChild("Humanoid")
							if(temp~=nil) and(human~=nil) and(human.Health>0) then
								if(temp.Position - position).Magnitude<dist then
									torso = temp
								end
							end
						end
					end return torso
	end
	print("function2 ready")
while wait(2) do
	print("WAHT DA HERR????")
	if script.Parent:FindFirstChild("Torso")~= nil then
	local target1 = script.Parent:FindFirstChild("Torso")
	print("OH GOD NOT THIS...")
		print("yaaaaassss")
	local target = findNearestTorso(target1.Position)
		if	NodeIsReady == true then
			print("function 3 ARE YOU READY!!!!")
			findNearestNode()
			print("I SEE THE LIGHT")
			if target ~= nil then
			script.Parent.Humanoid:MoveTo(target.Position, target)	
	end
	
		end
	end
end