How would I put Gamepasses script and a devProduct Script, together so that they both work?

I have had this issue before as well, but that was when I was putting separate devProducts scripts, but this time I have Game passes and a Single devProduct, how would I be putting them together, so that they both work?

1 Like

Since they’re both under the same service, it would make sense to put all the events, callbacks all in one script.

If it also answers your question, you can attempt using ModuleScripts which keep things concise.

Under one event/function you mean?

Well, here’s an example. Let’s say I had a ton of gamepasses.

gamepasses: 100, 101, 102, 103

To manage all of them, you can put them into a dictionary like so.

local MarketplaceService = game:GetService("MarketplaceService")

local gamepasses = {

gamePass1 = 100,

gamePass2 = 101,

gamePass3 = 102,

gamePass4 = 103

}

-- Storing the gamepass name as the key and the gamepass id as the value.

Hopefully this is still answering your question.

Hm, but what about a devProduct in their as well?

All right so the format for that is a bit different. Try to look at the comments I left and ask me any questions if need be.

-- Server Script

local MarketplaceService = game:GetService("MarketplaceService")

local gamepasses = {

gamePass1 = 100,

gamePass2 = 101,

gamePass3 = 102,

gamePass4 = 103

}

local devProducts = { -- dictionary of all the devproducts, their ID, and a function of what to do when product is purchased
	devproduct1 = {
		ID = 100,
		
		WhatToDo = function()
			-- do something
		end
	},
	
	devproduct2 = {
		ID = 101,
		
		WhatToDo = function()
			-- do something
		end
	},
	
	devproduct3 = {
		ID = 102,
		
		WhatToDo = function()
			-- do something
		end
	},
}

MarketplaceService.ProcessReceipt = function(purchaseInfo)
	for productName, product in pairs(devProducts) do -- looping through devproducts table
		if purchaseInfo.ProductId == product.ID then -- if the id in the table matches the ID that was passed then.
			product:WhatToDo() -- call it's what to do function
		end
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted -- MarketplaceService.ProcessReceipt must return this enum
end

Can you join those gamepasses and devProducts in one script for me please, I would understand it better then, my game is an obby, and I have gears which are passes and Skip Stage is a devProduct.

1 Like