Best approach for making AI

Hello, I am currently doing guard AI for a game I’m working on but I really need some advice in what approach should I use for this situation:

Basically I am trying to have many NPCs with the same code running at the same time, although I could just paste the same script in all of them, this is just absolutely awful and would ruin my game’s performance.

Do you guys have any ideas how could I make this in a more organized way?

Maybe make a handler that checks for anything that has the name as your npc and then write the ai.

You could put all NPCs in a folder, then just use

for _,npc in ipairs(NPCFolder:GetChildren())do
	--setup and do AI stuff
end

There’s also collectionService, and/or manually create tags with ids - but still iterating through them for setup.

1 Like