Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't marketplace service work?

I made a donate button and my friend tested it out. He payed and lost the robux but nothing shoed up in my account. It has been 17 hours, here is the code I am using:


MPS = game:GetService("MarketplaceService")
id = 1138688305
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	MPS:PromptProductPurchase(player, id)
end)

2 comments

1

Why are you doing this on the client? This is the most ineffective way to get any user a gamepass, or an item for that matter. Prompt the purchase on the server.

0

erm mate, you did not get the robux you mean? Read this article, you need to wait 3-7 days: https://devforum.roblox.com/t/incoming-adjustment-to-pending-sales-waiting-period/832724

1 answer

i see your script. if youre using a gamepass:

local productId = 1138688305
game.Players.PlayerAdded:Connect(function(player)
	Game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)

if its a devproduct:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local productID =  1138688305 -- Change this to your developer product ID
 
-- Function to prompt purchase of the developer product
local function promptPurchase()
	local player = Players.LocalPlayer
	MarketplaceService:PromptProductPurchase(player, productID)
end

after that you need to insert another script in serverscriptservice if youre using a devproduct to get the robux... you forgot that. but you have to add a benifit for that donation. how about 1 gold(lol)?

local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
 
-- Data store for tracking purchases that were successfully processed
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
 
-- Table setup containing product IDs and functions for handling purchases
local productFunctions = {}
-- ProductId 1138688305 for 
productFunctions[1138688305] = function(receipt, player)
	--we do this because there has to be some benefit in a devproduct.
	local stats = player:FindFirstChild("leaderstats")
	local gold = stats and stats:FindFirstChild("Gold")
	if gold then
		gold.Value = gold.Value + 1
		-- Indicate a successful purchase
		return true
	end
end
 --------------------------------------------------------------------------------------------------------------------------
--DO NOT TOUCH THIS SCRIPT FROM NOW ON OR ELSE YOU WILL NOT GET ROBUX!!!
-- The core 'ProcessReceipt' callback function
local function processReceipt(receiptInfo)
 
	-- Determine if the product was already granted by checking the data store  
	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
	local purchased = false
	local success, errorMessage = pcall(function()
		purchased = purchaseHistoryStore:GetAsync(playerProductKey)
	end)
	-- If purchase was recorded, the product was already granted
	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif not success then
		error("Data store error:" .. errorMessage)
	end
 
	-- Find the player who made the purchase in the server
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		-- The player probably left the game
		-- If they come back, the callback will be called again
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	-- Look up handler function from 'productFunctions' table above
	local handler = productFunctions[receiptInfo.ProductId]
 
	-- Call the handler function and catch any errors
	local success, result = pcall(handler, receiptInfo, player)
	if not success or not result then
		warn("Error occurred while processing a product purchase")
		print("\nProductId:", receiptInfo.ProductId)
		print("\nPlayer:", player)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
 
	-- Record transaction in data store so it isn't granted again
	local success, errorMessage = pcall(function()
		purchaseHistoryStore:SetAsync(playerProductKey, true)
	end)
	if not success then
		error("Cannot save purchase data: " .. errorMessage)
	end
 
	-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
	return Enum.ProductPurchaseDecision.PurchaseGranted
end
 
-- Set the callback; this can only be done once by one script on the server! 
MarketplaceService.ProcessReceipt = processReceipt

note: roblox does not handle these devproduct purchases, so you must NOT alter the core script. you do not need the above script for a gamepass.

This discussion is preserved as it was. New answers, comments, and votes are closed.