I'm having difficulties with my gamepass shop

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Check if player owns gamepass and badge and other type of assets

  2. What is the issue? Include screenshots / videos if possible!
    My issue is that I have a ingame shop where you can purchase knives, and some of them require a gamepass to unlock, but even by owning the gamepass the knife still remains locked

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried everything, looking at assettypeid, I just learned that GamePassService is depreciated, since roblox does not make any updates about this. I’ve tried looking pretty much everywhere on chrome but since chrome is very bad with researches I found nothing related to my issue, chatgpt is too old for newest studio updates too.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
My first issues were about PromptPurchaseFinished and PromptPurchase, which has been “depreciated” too so when I realised that my old prefectly working script wasn’t working anymore because of this I literally spent 5 hours figuring this out. After that I saw that the GAMEPASS purchase prompt was working, but it does not unlock my knife at all anymore, while before these studio updates it was working PERFECTLY. I’ll send you the code snippets next here

--Check passes
	if uid > 0 then --Don't check assets if the player is a guest!
		for asset_name, asset_list in pairs(_G.CheckForGamePasses) do
			for _, asset_id in pairs(asset_list) do pcall(function()
				local id = tonumber(asset_id)
				local a_dat = MarketplaceService:GetProductInfo(id)
				local a_type = a_dat.AssetTypeId
				local OK = false
				
				if a_type == 21 then
					OK = BadgeService:UserHasBadge(newPlayer.UserId , id)
				elseif a_type == 34 then
					OK = MarketplaceService:UserOwnsGamePassAsync(newPlayer , id)
				else
					OK = MarketplaceService:PlayerOwnsAsset(newPlayer , id)
				end
				
				if OK then
					if _G.PLAYER_SESSIONS[nm] ~= nil then
						if not _G.PLAYER_SESSIONS[nm].Owned_Passes[asset_name] then
							_G.PLAYER_SESSIONS[nm].Owned_Passes[asset_name] = true
								
							end	
						end						
					end					
				end) 
			end
		end
	end
--Code in each individual knife to unlock them with price, badge and gamepasses infos
local shopData = {
	Texture = 'rbxassetid://881563193';
	MeshSize = Vector3.new(.6, .6, .6);
	ItemDescription = "lol this is sample";
	ItemName = "Tix Knife";
	Price = 2400;
	TierName = "CUSTOM",
	OwnerData = {"0Nex_ss", "https://tr.rbxcdn.com/b5d3ebcd088d415413e0a11cd9f72cfe/352/352/Avatar/Png", "Texture Creator"},
}

local importance = 999
local PackName = "TixPack"

local function CanDisplay(PlayerData, name)
	if _G.CLIENT_DATA ~= nil and _G.CLIENT_DATA.PlayerSession ~= nil then
		return _G.CLIENT_DATA.PlayerSession.Owned_Passes[PackName] -- Name of the pack
	end
	return false
end

return {shopData, importance,CanDisplay,PackName} 
-- Code for the shop buy gamepass prompt :
game.MarketplaceService.PromptGamePassPurchaseFinished:connect(function(Player , Asset , Is)
	if _G.CheckForGamePasses ~= nil then
		if Is == true then
			for Name , Ids in pairs(_G.CheckForGamePasses) do
				if Ids[1] == tostring(Asset) then
					_G.PLAYER_SESSIONS[Player.Name]["Owned_Passes"][Name] = true
					_G.CheckForPassPlayer(Player)
				end
			end
		end
	end
end)

ev_BuyGp.OnServerEvent:connect(function(Player,GamepassName)
	if _G.CheckForGamePasses ~= nil then
		if _G.CheckForGamePasses[GamepassName] ~= nil then
			local ID = _G.CheckForGamePasses[GamepassName][1]
			if ID ~= nil then
				local S  ,e = pcall(function() game.MarketplaceService:PromptGamePassPurchase(Player , tonumber(ID)) end)
				if not S then warn(e) end
			end
		end
	end
end)
-- Code of where every gamepasses are set
_G.CheckForGamePasses = {
	DoubleGems = {"137398179"}, --2x G7
	
	QuadGems = {"137398362"},
	
	--AdminPass = {"0", "0"},
	
	EffectTrans = {"137398582"},
	
	--VipTag = {"0"},
	
	--RadioPass = {"0"},
	
	--Aboo = {"0"},
	
	--PhantomOutdated = {"0"},
	
	--GoldenOutdated = {"0"},
	
	--eggminlol = {"0"},
	
	--greenlas = {"0"},
	
	--outfather = {"0"},
	
	greenpack = {"137405532"},
	
	TixPack = {"137403426"},
	
	godlys = {"137398709"},
	
	spamgun = {"180264813"},
	
}

If you need more parts of the scripts I can send them to you.

1 Like

Please note that this issue is new for me, since before a certain update of roblox studio it broke my scripts.

I don’t really understand the use of global variables for the checkforgamepasses, when you could just create a modulescript, and I also don’t really see why you put each gamepass in a table. Also, CheckForGamePasses is not a function, so it will always return the table of gamepasses but not true or false.

CheckForGamePasses is used in multiple other scripts. I put each gamepass in a table to get all their IDs in that same table and they can be called from the knives scripts. I could’ve made for each knife a script that check if the player owns the needed gamepass, and then unlock it, but that would’ve took alot of time.

I made a new test, I replaced my “TixPack” gamepass ID with an other gamepass id to test if my scripts were broken or if my gamepass are not detected a second time after purchase, finds out that by making a new gamepass I have access to my knife.

I found a fix to my problem, instead of using this code :

--Check passes
	if uid > 0 then --Don't check assets if the player is a guest!
		for asset_name, asset_list in pairs(_G.CheckForGamePasses) do
			for _, asset_id in pairs(asset_list) do pcall(function()
				local id = tonumber(asset_id)
				local a_dat = MarketplaceService:GetProductInfo(id)
				local a_type = a_dat.AssetTypeId
				local OK = false
				
				if a_type == 21 then
					OK = BadgeService:UserHasBadge(newPlayer.UserId , id)
				elseif a_type == 34 then
					OK = MarketplaceService:UserOwnsGamePassAsync(newPlayer , id)
				else
					OK = MarketplaceService:PlayerOwnsAsset(newPlayer , id)
				end
				
				if OK then
					if _G.PLAYER_SESSIONS[nm] ~= nil then
						if not _G.PLAYER_SESSIONS[nm].Owned_Passes[asset_name] then
							_G.PLAYER_SESSIONS[nm].Owned_Passes[asset_name] = true
								
							end	
						end						
					end					
				end) 
			end
		end
	end

I’m using that :

if uid > 0 then -- Don't check assets if the player is a guest!
    for asset_name, asset_list in pairs(_G.CheckForGamePasses) do
        for _, asset_id in pairs(asset_list) do
            pcall(function()
                local id = tonumber(asset_id)
                local OK = false
                
                -- Check if the asset is a gamepass
                local success, isOwned = pcall(function()
                    return MarketplaceService:UserOwnsGamePassAsync(uid, id)
                end)
                
                if success and isOwned then
                    print(players.Name .. " owns the " .. asset_name .. " Gamepass.")
                    if _G.PLAYER_SESSIONS[nm] ~= nil then
                        if not _G.PLAYER_SESSIONS[nm].Owned_Passes[asset_name] then
                            _G.PLAYER_SESSIONS[nm].Owned_Passes[asset_name] = true
                            print(players.Name .. " now has access to " .. asset_name)
                        end
                    end
                end
            end)
        end
    end
end

My problem was apparently related to the use of AssetTypeID stuff. I removed that part and now it works as intended.

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