Forja

Roblox developer product script

For things players can buy again and again, like coins. The purchase is only marked done once they've got what they paid for.

Where it goes

  1. 1It adds to a stat called Coins: add the leaderboard script too, so players have one.
  2. 2On the Creator Dashboard, open your game, go to Developer Products under Monetization, make one and copy its ID.
  3. 3Add the first script to ServerScriptService, and put your ID in PRODUCT_ID. In StarterGui, add a ScreenGui with a TextButton and put the second script in it as a LocalScript, with the same ID.
SellCoins · a Script in ServerScriptService
-- From forja.us/tools/roblox-scripts/developer-product-- Gives coins for each purchase. Only one script in a game can set ProcessReceipt.local MarketplaceService = game:GetService("MarketplaceService")local Players = game:GetService("Players")local PRODUCT_ID = 0 -- your developer product's idlocal COINS = 100MarketplaceService.ProcessReceipt = function(receipt)	if receipt.ProductId ~= PRODUCT_ID then		return Enum.ProductPurchaseDecision.NotProcessedYet	end	local player = Players:GetPlayerByUserId(receipt.PlayerId)	local leaderstats = player and player:FindFirstChild("leaderstats")	local stat = leaderstats and leaderstats:FindFirstChild("Coins")	if not stat then		-- They left: Roblox tries again the next time they join.		return Enum.ProductPurchaseDecision.NotProcessedYet	end	stat.Value += COINS	return Enum.ProductPurchaseDecision.PurchaseGrantedend
BuyCoinsButton · a LocalScript in a TextButton in StarterGui
-- From forja.us/tools/roblox-scripts/developer-product-- Opens Roblox's window to buy the coins.local MarketplaceService = game:GetService("MarketplaceService")local Players = game:GetService("Players")local PRODUCT_ID = 0 -- your developer product's idscript.Parent.Activated:Connect(function()	MarketplaceService:PromptProductPurchase(Players.LocalPlayer, PRODUCT_ID)end)

How it works

  • ProcessReceipt runs after each purchase. Returning PurchaseGranted tells Roblox it's done.
  • Returning NotProcessedYet means Roblox tries again later, so nobody pays for nothing if they leave at the wrong moment.
  • Only one script in a game can set it. With more products, check each ProductId in this one.

Make it yours

Save the coins
Use the saving script, or a purchase is gone when they leave.
Want something more? The script generator can write it: “Three developer products that give 100, 500 and 1000 coins, all in one ProcessReceipt”

Maps to try it on: simulator and tycoon maps

Start from a finished map, and your scripts have a game to run in.

More free Roblox scripts