Hey so whenever i purchase my dev product for 500 gems, everything works fine, no errors but i just never get the gems. this is my devproduct script, is is on a server script and I think it is only this script as the prompt purchase works fine. Does anyone know how to fix it?
local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players
local Dev1kC = 1196082194
local function processReceipt(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if receiptInfo.ProductId == Dev1kC then
player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 500
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketPlaceService.ProcessReceipt = processReceipt
I am pretty sure your way of doing it is wrong, I don’t work on purchases much, but this should probably work?
local productFunctions = {}
productFunctions[1196082194] = function(receipt, player) -- add the function for 500 gems
player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 500
end
local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players
local function processReceipt(receiptInfo)
local player = game.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) -- failed
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
-- finish, success
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketPlaceService.ProcessReceipt = processReceipt
(most of the code is from developer.roblox.com) If it doesn’t work please tell me!
Oh my, so I was double checking the script and I had mistyped the id, I have fixed it and it still doesn’t work in studio but i’m going to test it in a public game
local productFunctions = {}
productFunctions[1196082194] = function(receipt, player) -- add the function for 500 gems
player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 500
return true
end
local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players
local function processReceipt(receiptInfo)
local player = game.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) -- failed
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
-- finish, success
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketPlaceService.ProcessReceipt = processReceipt
It just needed a return statement, hope you enjoy!
Are there any other scripts managing dev product purchases inside the place? There’s a chance they interfere with each other causing the issue(also the code must execute from a Script).
local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players
local Dev1kC = 1196082194
local function processReceipt(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if receiptInfo.ProductId == Dev1kC then
if player then
player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 500
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
end
MarketPlaceService.ProcessReceipt = processReceipt
What is the way the developer product is being prompted?
I made a version of the script that I tested in a server script and it worked flawlessly:
local productFunctions = {}
productFunctions[1233544200] = function(receipt, player) -- add the function for 500 gems
print("work")
return true
end
local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players
local function processReceipt(receiptInfo)
local player = game.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) -- failed
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
-- finish, success
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketPlaceService.ProcessReceipt = processReceipt
local p = game.Players:WaitForChild("forest_walker") -- dont do this
p.Chatted:Connect(function() -- hook it to the chat, normally it would be on a gui or something
MarketPlaceService:PromptProductPurchase(p, 1233544200)
end)
Yeah thanks this works, I think all of them must’ve worked but I deleted all the other Gem developer product scripts and it seems to work, do i need all of the same products to be in the same script?
local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players
local Dev1kC = 1196082194
local Dev2kC = 2392382392 -- random numbers
local function processReceipt(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if receiptInfo.ProductId == Dev1kC then
if player then
player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 500
return Enum.ProductPurchaseDecision.PurchaseGranted
end
elseif receiptInfo.ProductId == Dev2kC then
if player then
player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 1000
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
end
Also, make sure to mark my post as a solution so people know it’s solved :).
okay so it seems that the only way i can do it is with it all being in the same script, if I have more than 1 script even for another dev product it just doesn’t work