I'm inserting some in-game purchases in my game. I created all the Developer Products correctly, and I inserted all the necessary local scripts to prompt the purchases, and they work without any problem. I got this script from the developer page of Roblox in order to record all the transactions. However, when I test the game and I buy something, it doesn't do anything. It says that the purchase has been successfully completed, but then nothing happens. I tried to add a print message in the script several times in different positions, and it never printed anything. All the ProductIDs are right, I checked them several times. I also thought that maybe the problem was the fact that I inserted some "wait()" in the different productFunctions, but when I tried to remove them it still didn't work. I hope that someone can solve this. Thanks in advance. Here the script:
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
local productFunctions = {}
productFunctions[988367837] = function(receipt,player)
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed *3
wait(20)
player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed /3
return true
end
end
productFunctions[988368778] = function(receipt,player)
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.JumpPower=player.Character.Humanoid.JumpPower *3
wait(20)
player.Character.Humanoid.JumpPower=player.Character.Humanoid.JumpPower /3
return true
end
end
productFunctions[988370741] = function(receipt,player)
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.MaxHealth = 999999
player.Character.Humanoid.Health = 999999
local ForceField = Instance.new("ForceField",player.Character)
wait(20)
player.Character.Humanoid.MaxHealth = 100
player.Character.Humanoid.Health = 100
ForceField:Destroy()
return true
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

2 comments
maybe remove the "if not success or not result" to "if not success"
I tried... still not working, and it still doesn't give me any error in the output