If you already have a script that is controlling the NPCs now it would help if you could share it so we can understand what the script is doing that you wish to change.
For your target search function, instead of looping through all Humanoids in workspace, you should loop through game:GetService("Players"):GetPlayers() which returns an array of all the players.