Issues reading values in a table

Hello there, dear members! I’m currently having some issues reading all values from a table. I tried using the pair and ipairs functions, but none of them worked. For some reasons, the script display anything in the console. Here is my table:

Rooms_Settings = {
		Standard = {
			{Number = "101", nil},
			{Number = "102", nil},
			{Number = "103", nil},
			{Number = "104", nil},
			{Number = "105", nil},
			{Number = "106", nil},
			{Number = "107", nil},
			{Number = "108", nil},
			{Number = "109", nil},
			{Number = "110", nil},
		}
	},

… and here is my script:

--NOTE: This script must print "Standard".

local function LoadRooms()
	warn("Printing rooms...")
	for _, v in pairs(Configuration.Rooms_Settings) do
		wait()
		warn(v)
	end
	warn("Ended.")
end

LoadRooms()

Help would be greatly appreciated!
~ HyperD3v!

1 Like

I am not too sure what you are trying to do.
Can you explain a bit more?

1 Like

Replace _ with i and attempt to print the index, see what shows up
Also the wait() is quite unneccesary

Tried, here are the results.
image

Try re-naming the variables, not quite sure if it will work.

Fixed the issue! I only had to change warn(v) to warn(_).
Thanks to everyone who replied!

1 Like

What’s Configuration? I’m guessing Rooms_Settings is not being read due to variable naming, quite unsure.

Configuration was a module.

I would also recommend changing _ to i as _ has a different meaning.

I don’t suggest using _, you’ll get a variable error from it

1 Like

Thanks for telling me, I changed the variable!

1 Like

In case someone didn’t understand.

ModuleScript

local Table_Manager_Test = {
	Rooms_Settings = {
		Standard = {
			{Number = "101", nil},
			{Number = "102", nil},
			{Number = "103", nil},
			{Number = "104", nil},
			{Number = "105", nil},
			{Number = "106", nil},
			{Number = "107", nil},
			{Number = "108", nil},
			{Number = "109", nil},
			{Number = "110", nil},
		}
	}
}

return Table_Manager_Test

ServerScript

local Table_Manager_Test = require(game.ServerScriptService.Table_Manager_Test)

local Table = Table_Manager_Test.Rooms_Settings

local function LoadRooms()
	warn("Printing rooms...")
	for Key, Value in pairs(Table_Manager_Test.Rooms_Settings) do
		wait()
		print(Key)
	end
	warn("Ended.")
end

LoadRooms()

First of all I recommend checking out those links before reading!!!

https://education.roblox.com/en-us/resources/intro-to-module-scripts

https://education.roblox.com/en-us/resources/pairs-and-ipairs-intro

Once you check out those links and try your best to understand, come back to this reply and continue reading a brief explanation.

In his case he has a ModuleScript placed inside ServerScriptService which contains a dictionary!!!

The reason he is using pairs() in a for loop is because his table in a Module Script is actually a dictionary.

There are 3 types of tables.

  1. Array
  2. Dictionary
  3. Metatables [Powerful Tables]

He is looping through the dictionary with Key variable, Value variable and in the brackets of pairs() function he placed the location of that dictionary he is going to loop through.

In his case Key variable is _ which I don’t recommend using and Value variable is named v.

A dictionary contains a pair key-value variable, where key is the name of what you are defining and value is the actual value of that key.

In his case he made a mistake and wanted to print or warn the Value, but he actually wanted to print the Key. Key in the dictionary in the Module Script is Standard.

Thanks for reading! :grin:

2 Likes