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.
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')
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)
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.
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"])
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)
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
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)