Weird warning "Cannot iterate over a table without indexer"

I can’t find any record of this warning online, and I don’t understand it either, since the code looks to be fine, and nothing really weird is going on, other than that the script is in strict mode for luau…It was my understanding that it’s accepted practice to directly iterate over any table now, and this isn’t an unusual table at all.

Here’s a screenshot of the warning:

1 Like

You have to use pairs in order for this to work.

Example:

for _, Part in pairs(ClosePointParts) do
     Part:Destroy()
end

you could also do this:

for i = 1, #ClosePointsParts do
    ClosePointsParts[i]:Destroy()
end

But… why? Did Roblox roll-back their direct iteration update, or is there something different about this situation that makes it necessary?

This is probably a bug with how Luau interprets empty tables

If ClosePointParts is being populated with values then you can probably ignore this. I wonder if asserting the table’s type as {[number]: any} silences the warning though this seems like a non-type based error

5 Likes

Yep, that silenced it. I guess it was because I was initializing the table as empty, then this part of the function ran, before the table was getting filled with anything. The code was working fine, it was just strange it was warning me over it… Roblox should fix this warning, haha.

1 Like