id = 20518668 --dev product id
script.Parent.MouseButton1Click:connect(function(p)
game:GetService("MarketplaceService"):PromptProductPurchase(p, id)
local MarketplaceService = Game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
MarketplaceService.ProcessReceipt = function(receiptInfo)
if p.userId == receiptInfo.PlayerId then
if receiptInfo.ProductId == id then
p.leaderstats.Cash.Value = p.leaderstats.Cash.Value + 5000
end
end
-- record the transaction in a Data Store
local playerProductKey = receiptInfo.PlayerId .. "_got_" .. receiptInfo.PurchaseId
ds:IncrementAsync(playerProductKey, 1)
-- tell ROBLOX that we have successfully handled the transaction
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end)
COMMUNITY QUESTION
Why wont this work? Please help!
1 answer
local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
local link = game:GetService("MarketplaceService")
deb = 0
script.Parent.MouseButton1Click:connect(function()
local marketId = 0 --ID OF YOUR DEVELOPER PRODUCT
link:PromptProductPurchase(plr,marketId)
link.ProcessReceipt = function(receiptInfo)
if Enum.ProductPurchaseDecision.PurchaseGranted and receiptInfo.PlayerId == plr.userId then
if deb == 0 then
deb = 1
plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 1000 --Alter what stat you would like to increase or decrease after the player has purchased.
wait(1)
deb = 0
end
end
end
end)
-- record the transaction in a Data Store
local playerProductKey = receiptInfo.PlayerId .. "_got_" .. receiptInfo.PurchaseId
ds:IncrementAsync(playerProductKey, 1)
-- tell ROBLOX that we have successfully handled the transaction
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end)
put it in a text button or image button
2 comments
0
It is in a text button I click it and nothing shows up. Any ideas?
0
did you put the ID of the product?
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
What error do you get? Try F9 in online mode, then go into Server Console.