Humanoid.MoveToFinished not working properly

Currently working with mob’s being controlled using Humanoid:MoveTo(), but unfortunately it’s only working while in studio mode. As soon as I play using Play Solo, .MoveToFinished is not fired and the mob’s are not removed. Here’s a few gif’s to show what I’m working with.

facts
  • Script is a function within a module script.

  • No local scripts are used.

Studio Test working as expected.

https://gyazo.com/99fe0cfc77765905ac8789803f1da80e

Play Solo not working correctly.

https://gyazo.com/42cd7e5e4b02e151a1ff10d8b5322a95

Whether some or none of the mobs disappear is inconsistent. However, as soon as one doesn’t despawn upon reaching its finished - none disappear from there.

Code
local function MoveHumanoid()
				local target_reached = false
				local connection
				connection = EnemyHumanoid.MoveToFinished:Connect(function(reached) -- Not Firing.
					target_reached = true 
					connection:Disconnect()
					connection = nil
					if target_reached then
						print("Target reached") -- This is NOT printing. 
						if enemy then
							enemy:Destroy()
						end
						local remainder = 0
						if Core_Shield.Value > 0 then
							if Core_Shield.Value - Damage.Value > 0 then
								MainModule.DamageCoreShield(Damage.Value)
							elseif Core_Shield.Value - Damage.Value <= 0 then
								Core_Shield.Value = 0
							end
						end
						if Core_Shield.Value - Damage.Value < 0 then
							remainder = math.abs(Core_Shield.Value - Damage.Value)
						end
						if remainder > 0 and Core_Shield.Value <= 0 then
							MainModule.DamageCoreHull(remainder)
						end
					elseif Core_Shield.Value <= 0 and Core_Health.Value > 0 then
						MainModule.DamageCoreHull(Damage.Value)
					end
				end)	
				spawn(function()
					while not target_reached do
						wait()	
						
						local HumanoidState = EnemyHumanoid:GetState()
						if HumanoidState == Enum.HumanoidStateType.None then -- an attempt to fix when they stopped moving.
							MoveHumanoid()
						end
						
						
						if not EnemyHumanoid then 
							break
						end
						EnemyHumanoid:MoveTo(PhysCore.Position)
					end
				end)
			end
			MoveHumanoid()

If any more details are needed, feel free to ask.
Thanks for all contributions :slight_smile:

Can you print something directly inside of the MoveHumanoid function, and see if it prints?

Yup. It’ll print fine - and if I move the destination part they’re trying to get to, they will automatically update and try to move towards it. MoveHumanoid() is running fine - but for some reason when play testing [ live servers as well ], as soon as one mob can’t figure out when to stop - none of them know when to stop, therefore never triggering the .MoveToFinished event.