Query about CollectionService?

Hi, quick query about CollectionService.

So I’m using this to mark when a NPC has spawned in-game and following this it’ll then generate the follow Mechanic etc.

Eg:

CollectionService:GetInstanceAddedSignal("Marker"):Connect(function(Marker)
while true do wait()
-- Follow mechanic etc.
end
end)

So I assume that for each NPC this will create a new While true loop.
I was just wondering if this is the best way of doing so? Or will there be noticeable performance issues when say 15 NPCs spawn and having 15 while true do loops repeating.

what are you running inside the loop?

1 Like

Basic following;
i.e. checking magnitude to see if a Player is in range, if so then :MoveTo() etc.

No, I’ve run way more magnitude checks every frame. However, if it does become an issue (which would probably be around >100 players, or >1000 magnitude checks, assuming this is the client), look into spatial partitioning.