I have recently had the hardest time dealing with tables and collection service.
To be fair I can get this working but honestly it seems very dumb the way I am doing it.
Here is a basic script I made that loops NPCS:
local NPCTag = "NPC"
local NPCUtils = {}
function NPCUtils.NPCLoop()
local npcs = {}
for _, npc in pairs(CollectionService:GetTagged(NPCTag)) do
local npcName = npc
table.insert(npcs, npcName)
end
return npcs
end
return NPCUtils
Now I make a basic loop to make a clone for every NPC int he table in a different script (I am trying to modularize it).
local function DisplayQuestIndicators()
local npcs = NpcUtils.NPCLoop()
print(npcs)
for _, npc in pairs(npcs) do
print(npc)
local npcName = tostring(npc)
local npcModel = npcModels[npcName]
npcQuestIndicator.Adornee = npcModel
npcQuestIndicator.Enabled = true
local npcIndicatorModel = npcIndicatorModels[npcName]
npcIndicatorModel.default.Transparency = 0
end
end
task.spawn(function()
DisplayQuestIndicators()
end)
But this always only repeat once, unless I make a runservice connection repeat it for 0.1 seconds and then it works. But honestly I am so lost why all tables return only 1 time in every for loop I write. Am I just horrible at looping through tables?