Getting GamePassId from table

Hello, I’m making it so when the player joins the game, they get an attribute added called ‘‘Owns[GamePassName]’’. My question here is, how’d I get the GamePassId from the table instead of the GamePass name?

local gamePasses = {
	[222142153] = "Vip"
}

print(gamePasses["Vip"]) --I want the number to be printed!

Simple, flip the values around. Replace the Vip string with the id, and replace the id with the Vip string.

1 Like

Make a selector

local function getGamepassById(name)
    for id, gpName in gamePasses do if gpName == name then return id end
end

But its better to do what @RockyRosso suggested

1 Like

I need to know both number and string, I’m trying to use one table only to achieve this.

Then you could format your table like this:

local gamePasses = {
   {
       name = "Vip",
       id = 1234
   }
}

1 Like

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