How to make a gamepass to give a certain amount of gold?

I want to know how I could give gold to a user if they buy a gamepass. I’m currently low and doing this will help me profit out of the ads I spent on my game. How would I make it so that if you purchase a gamepass it will automatically give you gold. This would really help! This script is called “Data” here it is!

 Beli.Value = Beli11:GetAsync(Plr.UserId) or Beli.Value
	   Beli11:SetAsync(Plr.UserId, Beli.Value)
      Beli.Changed:connect(function()
	   Beli11:SetAsync(Plr.UserId, Beli.Value)
   end)

Thats only the part that makes the gold. The rest is all level stuff that I don’t really need to put. Thanks!!

Sir, this script saves data, not adds gold because of a gamepass.
You could read about this; it will help

https://create.roblox.com/docs/production/monetization/index
https://create.roblox.com/docs/production/monetization/developer-products

1 Like

Game passes are more recommended for recurring benefits. I’d recommend using a developer product for a single transaction unless you want a game pass that provides recurring benefits aswell as the one time free gold opportunity.

This is relevant to your question because if you are planning to do this with a gamepass, you will need to save in the player’s datastore that they have already received the one time benefits which you would not have to do with a developer product.

Please get back to me on this one and I’ll try my best to help you.

@signupredirectlol it helps thanks! Also @ArgonTheory I’m good at when people gimme script instead of explaining cuz im not the best at scripting. I also want to ask how to make a gamepass you can buy many times. Like dungeon quest with their gold system

You can make a developer product by navigating to Configure Experience → Developer Products and then creating it from there. After you’ve made your developer product you will have to prompt the user to purchase it on the client, and then handle the transaction on the server (giving gold in your case).

On the client, prompting the user to purchase a developer product would look something like this:

local player = game:GetService("Players").LocalPlayer
local MarketplaceService = game:GetService("MarketplaceService")
local productId = 0 -- Replace this with your developer product ID

MarketplaceService:PromptProductPurchase(player, productId)

Prompts for developer products could also be done on the server. For example when interacting with a surface gui. In most cases you will only be needing to be using it on the client.

Now you’ll need a way for the server to actually give the compensation for the purchase.

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

local GoldDatastore = DataStoreService:GetDataStore("GoldDatastore")

local productFunctions = {}

productFunctions[YOUR_PRODUCT_ID] = function(receiptInfo, player)
	--give gold here
end

local function processReceipt(receiptInfo)
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	local handler = productFunctions[receiptInfo.ProductId]
	local success, err = pcall(handler, receiptInfo, player)
	
	if not success then
		warn("Error occurred while processing a product purchase")
		print("\nProductId:", receiptInfo.ProductId)
		print("\nPlayer:", player)
		
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end


MarketplaceService.ProcessReceipt = processReceipt

This script is on the server. The processReceipt event is fired when a Player purchases a developer product.

Thanks! I’ll go try it out after I finish some new updates