I was too lazy to write my own ProcessReciept
script so I copied the one from Roblox. Unfortunately, it is not working. I used to always work but it just stopped - its killing me.
Main Script:
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local values = game.ReplicatedStorage:WaitForChild("Values")
-- 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 = {}
-- immunity
productFunctions[1200817842] = function(receipt, player)
print("IM")
values.Immunity.Value = true
return true
end
-- teleport
productFunctions[1200817843] = function(receipt, player)
print("TEL")
return true
end
-- speed
productFunctions[1200818032] = function(receipt, player)
print("SPEED")
values.Speed.Value = true
return true
end
-- jump
productFunctions[1200817844] = function(receipt, player)
print("JUMP")
values.LowGravity.Value = true
return true
end
-- 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
The prompt script (its the same for every gui button but not the same id)
local id = 1200817842 -- immunity
local ms = game:GetService("MarketplaceService")
script.Parent.Activated:Connect(function()
ms:PromptProductPurchase(game.Players.LocalPlayer, id)
end)
The prompt works, but the process does not. I have used Roblox’s script multiple times but it now does not work. I have tried using print()
to find out how I where the error might be (there are no errors in the output). The print() statements in the product functions (located in the main script) do not print…