Humanoid:MoveTo() cause npc teleport when working with around 100 npc

  1. i would love to know why Humanoid:MoveTo() causes npc teleport when working with around 100 npc

  2. i simply loop through all npc with tag name and check if any player nearby, if there is one, i call Humanoid:MoveTo(Player RootPart position)

1 Like

Does this conviently happen after 8 seconds?

i think it starts happening from the 70th npc

https://gyazo.com/17b720ff587e664e15009834c5485ffd. at 5 second, you can see some npc teleport to me instead of moving to me

for each npc, i have this wrapped with a coroutine.wrap

		while true do
		
			--warn("aka")
			if banditTable[model] and not banditTable[model].target then
				warn("no target yet")
				for _, player in pairs(game.Players:GetPlayers()) do
					-- For example, checking if player is close to the model
		
					if (player.Character and (checkDist(player.Character.HumanoidRootPart.Position,  model.PrimaryPart.Position) < 50)) then
						banditTable[model].target = player.Character
						model.Humanoid:MoveTo(banditTable[model].target:FindFirstChild("HumanoidRootPart").Position)
							warn(banditTable[model])					
					end
				end
                task.wait(0.2)
            end

Having that many NPCs Humanoids in a game might be lagging it and causing the issue.
Try opening the Server MicroProfiler to see if that’s what’s happening.

Yeah that normal it’s hard to have a lot of npc moving at the same time but you can improve performance by :

  • Set collision between players and npc, npc and npc false using Physics service
  • if the npc isn’t active anchor his HumanoidRootPart
  • (must understand before doing anything and be sure) SetNetworkOwner of HumanoidRootPart to a player so the server does less work and the npc for that player will be smooth but you have to understand what it is before adding that

But to be honest it’s hard having more than 100 npc moving at the same time