Hello, I don’t quite know how to use pairs and ipairs and i don’t know if this edit is wrong because with it it doesn’t work anymore.
This is the original script
I don’t even understand your issue. ipairs is an iterator that runs through the provided table and returns an index and a value, in that order. What ??
NPCFolder doesn’t exist in my game, so i have to replace it with npc, which exists instead. My question is if there is any way to replace ipairs with something else because it clearely doesn’t work with “npc”
You haven’t showed us what “npc” is, like what type of data it points to. If npc is a table with an array part containing a list of NPCs, then ipairs will work. If it’s anything else (single NPC, table that’s a dictionary, string, etc.) it won’t. It’s as simple as that, ipairs iterates over the array part of a table, and GetChildren() always returns a table that has only an array part, no dictionary, which is why it’s used there. pairs will loop over all of the keys in a table, even if it’s a mix of array indices and dictionary keys.
Well that still doesn’t tell me what NPC is, but it tells me it’s an Instance type that can be parented to the datamodel (Workspace), which means it’s not a Lua table. ipairs and pairs are for iterating over Lua tables.
Secondly, if it’s just one NPC, why do you need a loop?!
Just delete the whole for loop line, and corresponding end, and hard-code whatever is in the body of the loop to reference just npc instead of the loop variable NPC.