My code skips my For Loop

Hello Developers!

I need help with my script. I’m making a script and I’m trying to see how many objects I have in a table. I created my table in the script (That means I didn’t create a folder).

fyi this is in a Function

print("Done imageID")
	
for i, v in pairs(GroupInfo) do
	print("For loop")
	print(v)
end
print("End of Function...")

So I do know my script skips my For Loop because in my Output I get “Done imageID”,"End of Function..."

1 Like

Could you show us what GroupInfo is?

GroupInfo is a table I created in my Server Script.

local GroupInfo = {
	
	
	
}

It’s empty in the beginning of my script.

I add stuff inside my doing table.insert(GroupInfo, filteredText[1]) later in my code

Alright. Could you add a print just before your for-loop and print out the table GroupInfo? Tell me what shows up in the output.

A for loop can run zero times if its iterator contains nothing. In this case if GroupInfo is empty it will run zero times.

2 Likes

I get brackets when I add print()
aka “{}”

print("Done imageID")
	
print(GroupInfo)
for i, v in pairs(GroupInfo) do
	print("For loop")
	print(v)
end
	
print("End of Function...")

That means GroupInfo has nothing in it, like @azqjanna mentioned

2 Likes

Okay - {} means that your table is empty, it has nothing inside of it. Obviously, it now makes sense why your for loop gets skipped: Roblox runs your for loop, but sees that the thing you’re looping over is empty - there isn’t anything to loop over. That is why it seems like it just gets “skipped” (as the people above me explained correctly).

The issue seems to be with the way you’re inserting data into your table, that’s where you have to investigate further.

1 Like

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