Locate an item in a table

Hello! What I’m trying to do is I am trying to find the player’s username in the table, and list the rank they are assigned to. How can I do that?

local admins = {
	["Limited"] = {},
	["Moderator"] = {},
	["Administrator"] = {},
	["Developer"] = {"LMVM2041"},
	["Owner"] = {}
}

I think the only thing would be to use loops:

local admins = {
	["Limited"] = {},
	["Moderator"] = {},
	["Administrator"] = {},
	["Developer"] = {"LMVM2041"},
	["Owner"] = {}
}

for rank, usernames in pairs(admins) do
    if table.find(usernames, player.Name) then
        print("YES")
    end
end
2 Likes

Use nested for loops:

local admins = {
	["Limited"] = {},
	["Moderator"] = {},
	["Administrator"] = {},
	["Developer"] = {"LMVM2041"},
	["Owner"] = {}
}

local function getRank(player_name)
	for rank, names in pairs(admins) do
		for _, name in pairs(names) do
			if player_name == name then
				return rank
			end
		end
	end
	
	--If no rank return nil
	return nil
end
1 Like

This works perfectly! Thanks a lot for your help!

1 Like