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

Why does this script not trigger when Dev Product was purchased?

Hey, I am trying to make a script which processes a Developer product. Now, the purchasing works, but the script does not trigger. I don't get errors either.

local market = game:GetService("MarketplaceService")
local Https = game:GetService("HttpService")
local function processreceipt(receiptInfo)
	print("received it")
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		local id = receiptInfo.ProductId
		if not plr then
			return Enum.ProductPurchaseDecision.NotProcessedYet
		else
		
		print("Purchased!"
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end

market.ProcessReceipt = processreceipt

It does not print "received it".

3 comments

0

You can only set one ProcessReceipt. Any other assignment will override the current function

0

Okay, but I only have this one function in the game. Do I understand something wrong?

0

why does https exist?

1 answer

Here's some code from the official Roblox page that I edited to work, change the ID to whatever dev purchase happens and change what it does below the 'then'. You can add more of them if needed I haven't tested it yet.

local MarketplaceService = game:GetService("MarketplaceService")

local Players = game:GetService("Players")
local function getPlayerByUserId(userId)
	for _, player in pairs(Players:GetPlayers()) do
		if player.UserId == userId then
			return player
		end
	end
end

local function processReceipt(receiptInfo)
 
	-- Find the player who made the purchase in the server
	local player = game:GetService("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
 
	-- Output what product they bought
	if receiptInfo.ProductId == 940739628 then
		player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 50
	else
		print("do nothing")
	end
	print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)
 
	-- 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

Please accept if this solves your problem. If you have any questions please feel free to ask in the comments.

1 comment

0

pls accept Oh yea and this goes in ServerScriptService as a normal script.

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