-- Local Functions

local function moveToAndWait(humanoid, targetPosition)
	local targetReached = false
	local runningThread = coroutine.running()
	local connection1 = humanoid.MoveToFinished:Connect(function(reachedTarget)
		if reachedTarget then
			targetReached = true
			coroutine.resume(runningThread)
		end
	end)
	local connection2 = humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
		humanoid:MoveTo(targetPosition)
	end)
	humanoid:MoveTo(targetPosition)
	coroutine.wrap(function()
		while not targetReached do
			wait(6)
			if not humanoid.Parent or humanoid.WalkToPoint ~= targetPosition then
				break
			end
			humanoid:MoveTo(targetPosition)
		end    
	end)()
	coroutine.yield()
	connection1:Disconnect()
	connection2:Disconnect()
end
