How to get the index of a table

So, i’m gonna be frank, I want to get the index of a table within a table, dictiory is you want.

So this is my script:

dict = {
		["Map1"] = {"Player1, Player2"};
		["Map2"] = {"Player3"};
		["Map3"] = {};
		["Map4"] = {"Player4"};

		}

local function findValue(dictionary, valueToFind)

		for i, v in pairs(dictionary) do


			if v == valueToFind then

			return dictionary

			end


			if typeof(v) == "table" then

			return findValue(v, valueToFind)

			end

	

		end

	for key,value in pairs(dict) do
     if typeof(dict[key]) == "table" then
       for _,v in pairs(value) do
               if value == valuetofind then
              return key

			end

	return false

end

print(table.find(dict, findValue(dict, "Player4")))

So when i return dictioanry, I kinda get the table where Player4 was located in. But, It gives it like this: table: 123412314jdsjfsh (something like that).

And it doesnt give me the index either.

SO I was wondering how I could get the index of the table where the “Player4” (or whatever I search for) is located.

So In this case, I should print: 4, because it is the last and fourth table in the dictionary.

Also, this a recursive functin, so It deep searches the whole dict.

Thank you and feel free to ask question! Thank you alot!

for tables, when you do for i,v in pairs() i is the index so it should be something like this:

local dict = {
	["Map1"] = {"Player1, Player2"};
	["Map2"] = {"Player3"};
	["Map3"] = {};
	["Map4"] = {"Player4"};
}

for i,v in pairs(example) do
for _,b in pairs(v) do
if b == "Player4" then
print(i)
end
end
end

I just redid this script for getting the tables and checking if its “Player4”.

Are you trying something like this?

local mapsInfo = {
	["Map1"] = {"Player1", "Player2"},
	["Map2"] = {"Player3"},
	["Map3"] = {},
	["Map4"] = {"Player4"}
}

print(mapsInfo.Map4[1]) --> "Player4"

That’s easy, table.find(table, valueToFind) returns the index of the first valueToFind that was found, if can’t find it returns nil

Yes, this would work normally but this is a dictionary and he wants to find the player and get the map it is in. table.find does not work well for dictionaries and the way he is trying to use it.

He’s trying to get the index, and I believe table.find would work well to just get the index.

local mapsInfo = {
	["Map1"] = {"Player1", "Player2"},
	["Map2"] = {"Player3"},
	["Map3"] = {},
	["Map4"] = {"Player5", "Player4"}
}

print(table.find(mapsInfo.Map4, "Player4")) --> "2"

yes, but he wants to get which map the player is in and he most likely plans to look for multiple players. He wanted to get the map the player is assigned to. not to just look for it and get the position itself.