My Client
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productID = 995097904
local function promptPurchase()
local player = Players.LocalPlayer
MarketplaceService:PromptProductPurchase(player, productID)
end
script.Parent.MouseButton1Click:Connect(promptPurchase)
My Server Code
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
local productFunctions = {}
--[[productFunctions[IDHERE] = function(receipt, player)
end]]
productFunctions[995097904] = function(receipt, player)
local stats = player:FindFirstChild("leaderstats")
local Stage = stats and stats:FindFirstChild("Gold")
if Stage then
local humanoid,hrp = player.Character:WaitForChild("Humanoid"), player.Character:WaitForChild("HumanoidRootPart")
player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
local part = workspace.ObbyStages:FindFirstChild(Stage.Value)
hrp.CFrame = part.CFrame + Vector3.new(0,1,0)
end
end
local function processReceipt(receiptInfo)
local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
local purchased = false
local success, errorMessage = pcall(function()
purchased = purchaseHistoryStore:GetAsync(playerProductKey)
end)
if success and purchased then
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif not success then
error("Data store error:" .. errorMessage)
end
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local handler = productFunctions[receiptInfo.ProductId]
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
local success, errorMessage = pcall(function()
purchaseHistoryStore:SetAsync(playerProductKey, true)
end)
if not success then
error("Cannot save purchase data: " .. errorMessage)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
I get the error: Error occurred while processing a product purchase (I'm in test mode in Roblox Studio by the way.)
