Hey, there.
I’m having this issue, where whenever I have a for loop to loop through a table/dictionary, and there is nothing stored in it yet, it will error. Is there any easy fix to this?
Optimally, I’d want it to try and loop and just skip it, as there is nothing to loop through/the table is empty.
Here’s what the loop would look like:
for _, Value in pairs(Data["Pets"]["PetsUnlocked"]) do
end
Yeah, alright.
That’s what I was going to do, just that there are a lot of loops in my game like that, and they all error, so its a lot of if statements. But I guess I’ll just go the route of doing that.
That’s extremely odd. Data.Pets.PetsUnlocked exists and isn’t nil. pairs works just fine on empty tables. If you run across a table that would make your pairs error and you try to do
if Data["Pets"]["PetsUnlocked"][1] then
to it, then that will error as well, because you’d still be doing nil[1].
It must be that Data.Pets.PetsUnlocked just doesn’t exist and wasn’t added to the table, or there is a typo, or you are using the wrong table.