Gamepasses are not working in my script

This is a local script inside Gui. Every time id is a gamepass id it prints:

Invalid Asset Type. Expected a shirt, t-shirt, game pass, or pants but got 9

And does not work, but if it is a shirt, pants, t-shirt id no issue occur. How can I Make Gamepasses work?

local function validateProduct(id)
	local success, info = pcall(function()
		return MarketplaceService:GetProductInfo(tonumber(id))
	end)

	if success and info then
		-- Debug print for AssetTypeId
		print("AssetTypeId for ID", id, "is", info.AssetTypeId)

		-- Check if the asset is a shirt, t-shirt, game pass, or pants
		local validAssetTypes = {
			[11] = "Shirt",      -- AssetTypeId 11 for shirts
			[12] = "Pants",      -- AssetTypeId 12 for pants
			[2] = "T-Shirt",     -- AssetTypeId 2 for t-shirts
			[34] = "Game Pass",  -- AssetTypeId 34 for game passes
		}

		if validAssetTypes[info.AssetTypeId] then
			if info.IsForSale and info.PriceInRobux and info.PriceInRobux >= 10 then
				return true, validAssetTypes[info.AssetTypeId]
			else
				return false, "Item is not for sale or has an invalid price."
			end
		else
			return false, "Invalid Asset Type. Expected a shirt, t-shirt, game pass, or pants but got " .. info.AssetTypeId
			
		end
	else
		return false, "Failed to get product info. Error: " .. tostring(info)
	end
end

I also added print statements to make sure id is the correct gamepass id

1 Like

The problem is likely due to the way game passes are handled in the Roblox API. Game passes use a different method for retrieving information compared to other assets like shirts or pants.

local MarketplaceService = game:GetService("MarketplaceService")

local function validateProduct(id)
    local success, info
    local isGamePass = false

    -- First, try to get info as a regular asset
    success, info = pcall(function()
        return MarketplaceService:GetProductInfo(tonumber(id))
    end)

    -- If it fails, try as a game pass
    if not success or info.AssetTypeId == 9 then
        success, info = pcall(function()
            return MarketplaceService:GetProductInfo(tonumber(id), Enum.InfoType.GamePass)
        end)
        isGamePass = true
    end

    if success and info then
        print("AssetTypeId for ID", id, "is", info.AssetTypeId)

        local validAssetTypes = {
            [11] = "Shirt",
            [12] = "Pants",
            [2] = "T-Shirt",
            [34] = "Game Pass",
        }

        local assetType = isGamePass and "Game Pass" or validAssetTypes[info.AssetTypeId]

        if assetType then
            if (isGamePass or info.IsForSale) and info.PriceInRobux and info.PriceInRobux >= 10 then
                return true, assetType
            else
                return false, "Item is not for sale or has an invalid price."
            end
        else
            return false, "Invalid Asset Type. Expected a shirt, t-shirt, game pass, or pants but got " .. info.AssetTypeId
        end
    else
        return false, "Failed to get product info. Error: " .. tostring(info)
    end
end
1 Like