Edit:
The solution was that I was actually looping correctly, it was that the loop was ending. I didn’t know this until I used the correct print statements and commented out each line. Noticed it stopped printing the NPC names and stopped at the first one when it was false. Switched my condition to if not then continue end (not return end).
Some reason when I do a basic loop through my NPCs it always returns the last npc.
It doesn’t even touch the first one or second one.
for index, npc in pairs(NPCTag) do
local npcName = tostring(npc)
print(npcName)
end
It only prints out 1 npc and that is it. What am I missing? I feel it is something simple. I’d like it to go through each npc in the game and I thought tagging them but I might be using collection service wrong as well. Yes all NPCS have a tag, and yes I am using the CollectionService:GetTagged(“NPC”).
Ignore this, it does not related to CollectionService, assuming NPCTag = CollectionService:GetTagged(“NPC”) you should be dealing with an array.
By chance does each NPC have the same name and the console has consolidated the print into one line? You would see a multiplier (x2,x3) alongside with it.
Otherwise all I can recommend is posting more of your code, its possible that NPCTag was not accessed correctly.
EDIT: For sakes of debugging print the list of NPCTag by doing print(#NPCTag), that will also help resolve possible points of error.
So it prints 2 npcs with tags, I remove one from another NPC just to see so that is correct, it does indeed see 2 things with tags, and if I do print(NPCTag)
It shows the table of both NPC’s index as [1] and [2].
Something is odd tho, just now it looped through both. So maybe it was just never showing me it looped through the other 2 NPCs?
As for reference I am having it loop through each NPC that is tagged and then finding the quest they have, and printing if the player has accepted it or not. That part is working but I just never noticed it I guess until now. I did comment out my function at the bottom though…