Navigating a table with a variable instead of a number

  1. Say I wanted to navigate a table by using [1], [2] etc. For example, table[1] would retrieve the info in that particular area of the table.

  2. What is the issue? I do not know how to achieve this, I get an error.

  3. What solutions have you tried so far? Getting a variable of a number and tonumber the variable using it. I get nil when doing this though.

local table = {
[1] = {
["Name"] = "balablala"
}
}

local number = tonumber(player.PlayerGui.BankManagement.EditLoan.Number.Value)

print(result[number]["Name"])

I don’t quite understand what you are trying to achieve. Is the variable a number or a string?

it’s a number variable under a GUI

Are you sure that the number match what inside the table a.k.a the number being 1?

local result = {
	[1] = {
		["Name"] = "balablala"
	}
}

local number = 1

print(result[number]["Name"])

print(result)

output:

 balablala  -  Server - Script:9
  12:59:04.950   ▼  {
                    [1] =  ▼  {
                       ["Name"] = "balablala"
                    }
                 }  -  Server - Script:11

Im using a number value as the variable, not using local

Do you mean a NumberValue instance?

local numberValue = workspace.Value --Path to NumberValue/IntValue instance.

local dict = {
	{["Key"] = "Value"}
}

print(dict[numberValue.Value].Key) --Value

For this example to work I had a NumberValue instance placed inside the workspace container. The value of its “Value” property was set to 1.