Table of Gamepasses

So I wanted to know if it’s possible to write out a table of gamepass Id’s, and make each of them have it’s own function.

For example:

local gamePassID = {
	money_multiplier = 00000,
	infinite_backback = 00000,
	autoclicker = 00000
}

local function onPlayerAdded(player)
	local hasPass = false
	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserID, gamePassID)
	end)
	
	if hasPass then
		if gamePassID == money_multiplier then
			
		end
	end
end

Something like this. I know this doesn’t work but I think I get the point across.

How can I achieve this?

You could do it with

if passID == gamePassID['money_multiplier']

or, you could assign each ID its own function inside of a dictionary, i.e.

local function other_function(arg)
    print(arg)
end

local gamepass_functions = {
    [1234284] = function(arg)
        print(arg)
    end,
    [2314888] = other_function
}

local pass_id = 2314888

gamepass_functions[pass_id]('hi')

1 Like

So I tried using

and it didn’t work. I don’t know if it’s because I didn’t do it properly but here is my script. If you can tell me what’s wrong I’d really appreciate it.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = {
	money_multiplier = 69544154,
	infinite_backback = 69544266,
	autoclicker = 69545150
}

local function onPlayerAdded(player)
	local hasPass = false
	local multiplierfolder = player:WaitForChild("mf")
	
	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserID, gamePassID)
	end)
	
	if hasPass then
		if gamePassID == gamePassID["money_multiplier"] then
			local moneyMultiplier = multiplierfolder:WaitForChild("moneyMultiplier")
			moneyMultiplier.Value = moneyMultiplier.Value*2
		end
	end	
end

Players.PlayerAdded:Connect(onPlayerAdded)

You’re trying to use gamePassID as the id to check while using the same variable as your table

gamePassID == gamePassID["money_multiplier"]

Define another variable like idToCheck and use it.

local idToCheck = gamePassID["money_multiplier"]

So like

local mm = gamePassID["money_multiplier"]
if mm == gamePassID["money_multiplier"] then

?

(So sorry for asking so much. I haven’t really delt with gamepasses and developer products as much)

1 Like

Yep, and no problem.

characters

1 Like

Ok so quick problem. I implemented everything into the script and just to make sure it worked, I used a print statement after the if mm == gamePassID["money_multiplier"] then except it didn’t print anything even though I had the gamepass.

Did you forget to change gamePassID to mm in UserOwnsGamepassAsync?

this makes no sense why would you check to see if a dictionary of gamepass id’s is equal to a value

That was a mistake on my part. I misread what he had posted.

If I set it to mm wouldn’t the entire function only be able to be used by that one gamepass?

Yes but you could set multiple variables and use else if statements.

I’m a little confused can you give me an example?

This is what you should be using l:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassIDs = {
	money_multiplier = 69544154,
	infinite_backback = 69544266,
	autoclicker = 69545150
}

local function onPlayerAdded(player)
	local hasPass = false
	local multiplierfolder = player:WaitForChild("mf")
	
	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserID, gamePassID)
	end)
	
	if hasPass then
		if gamePassID == gamePassIDs["money_multiplier"] then
			local moneyMultiplier = multiplierfolder:WaitForChild("moneyMultiplier")
			moneyMultiplier.Value = moneyMultiplier.Value*2
		end
	end	
end

Players.PlayerAdded:Connect(onPlayerAdded)

Then you could use the else if statement to check if the gamePassId is equal to something else (like gamePassIDs["infinite_backpack"])

If I do that it underlines gamePassID in orange and won’t work

You know what, here try this:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassIDs = {
	money_multiplier = 69544154,
	infinite_backback = 69544266,
	autoclicker = 69545150
}

local function onPlayerAdded(player)
	local hasPass = false
	local multiplierfolder = player:WaitForChild("mf")
	
    for gamePassName, gamePassID in pairs(gamePassIDs) do
        local success, message = pcall(function()
		    hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserID, gamePassID)
	    end)
        if hasPass then
		    if gamePassName == "money_multiplier" then
			    local moneyMultiplier = multiplierfolder:WaitForChild("moneyMultiplier")
			    moneyMultiplier.Value = moneyMultiplier.Value*2
		    end
	    end	
    end
end

Players.PlayerAdded:Connect(onPlayerAdded)

Edits: Fixing formatting

I tried this and added print statements to check where it might break at

		if hasPass then
			print("success")
			if gamePassName == "money_multiplier" then
				print("Has Gamepass")
				local moneyMultiplier = multiplierfolder:WaitForChild("moneyMultiplier")
			end
		end	

Nothing printed…

Wait, try this:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassIDs = {
	money_multiplier = 69544154,
	infinite_backback = 69544266,
	autoclicker = 69545150
}

local function onPlayerAdded(player)
	local multiplierfolder = player:WaitForChild("mf")
	
    for gamePassName, gamePassID in pairs(gamePassIDs) do
        print(gamePassName, gamePassID)
        local hasPass = false
        local success, message = pcall(function()
		    hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserID, gamePassID)
	    end)
        print(hasPass, success, message)
        if hasPass then
            print("Has Gamepass:", gamePassID)
		    if gamePassName == "money_multiplier" then
                print("Has Money_Multiplier Gamepass")
			    local moneyMultiplier = multiplierfolder:WaitForChild("moneyMultiplier")
			    moneyMultiplier.Value = moneyMultiplier.Value*2
		    end
	    end	
    end
end

Players.PlayerAdded:Connect(onPlayerAdded)

My head is literally exploding right now. This still didn’t print anything which confuses me even more because the script seems to make sense.

I’ll try printing for every single step