Using 'ipairs' on a table without an array part is likely a bug

I’m currently following a tutorial to learn scripts, and this problem suddenly popped up and I don’t understand why, I tried to look for the solution in the forum but I don’t understand the problem…

the other day it was with a scripter (with a good level) who didn’t know how to correct it

Can you explain to me?

I’ve already made an answer to another problem like this a short while ago:

Basically, tables have two types: Arrays and Dictionaries.
They’re technically the same, however, they cause different behaviors in loops.

For your problem, use: for tool, toolTable in toolConfig do and that should solve your issue.

3 Likes

For dictionaries you must use pairs instead of ipairs:

for tool, toolTable in pairs(toolConfig) do --pairs not ipairs!
1 Like

Yes, but why in the tutorial he do that and without error ? i dont understand that

Was it over 2 years ago?

image
image

Dictionaries and Arrays worked the same for many years, that’s a faulty tutorial.

using pairs() is quite unnecessary nowadays, as Luau now automatically handles that internally. Just using for tool, toolTable in toolConfig do would be enough.

6 Likes

That warning is pretty recent I think. I believe it came with the lua type checking stuff, now that it is able to determine the types of a table (having string indexes, rather than number indexes), it is able to throw a warning when you try to use ipairs on a table that doesn’t have number indexes

1 Like

Luau can’t loop over a string or other types of indexes (keys), only with number indexes it is able to find the value. Because a string can be anything wheres a number is a number. Otherwise, Dictionaries and Arrays are pretty much the same.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.