Advertisement
Jackthehunter25

Untitled

Nov 27th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. local MarketplaceService = game:GetService("MarketplaceService")
  2. local DataStoreService = game:GetService("DataStoreService")
  3. local Players = game:GetService("Players")
  4.  
  5. local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
  6.  
  7. local productFunctions = {}
  8.  
  9. productFunctions[1088662111] = function(receipt, player)
  10. local stats = player:FindFirstChild("leaderstats")
  11. local Coins = stats and stats:FindFirstChild("Coins")
  12. if Coins then
  13. Coins.Value = Coins.Value + 100
  14.  
  15. return true
  16. end
  17. end
  18.  
  19. productFunctions[1118688140] = function(receipt, player)
  20. local stats = player:FindFirstChild("leaderstats")
  21. local Coins = stats and stats:FindFirstChild("Coins")
  22. if Coins then
  23. Coins.Value = Coins.Value + 500
  24.  
  25. return true
  26. end
  27. end
  28.  
  29. productFunctions[1118688247] = function(receipt, player)
  30. local stats = player:FindFirstChild("leaderstats")
  31. local Coins = stats and stats:FindFirstChild("Coins")
  32. if Coins then
  33. Coins.Value = Coins.Value + 1250
  34.  
  35. return true
  36. end
  37. end
  38.  
  39. productFunctions[1118688441] = function(receipt, player)
  40. local stats = player:FindFirstChild("leaderstats")
  41. local Coins = stats and stats:FindFirstChild("Coins")
  42. if Coins then
  43. Coins.Value = Coins.Value + 2000
  44.  
  45. return true
  46. end
  47. end
  48.  
  49. productFunctions[1118688565] = function(receipt, player)
  50. local stats = player:FindFirstChild("leaderstats")
  51. local Coins = stats and stats:FindFirstChild("Coins")
  52. if Coins then
  53. Coins.Value = Coins.Value + 2800
  54.  
  55. return true
  56. end
  57. end
  58.  
  59. productFunctions[1118688866] = function(receipt, player)
  60. local stats = player:FindFirstChild("leaderstats")
  61. local Coins = stats and stats:FindFirstChild("Coins")
  62. if Coins then
  63. Coins.Value = Coins.Value + 4000
  64.  
  65. return true
  66. end
  67. end
  68.  
  69. local function processReceipt(receiptInfo)
  70.  
  71. local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
  72. local purchased = false
  73. local success, errorMessage = pcall(function()
  74. purchased = purchaseHistoryStore:GetAsync(playerProductKey)
  75. end)
  76.  
  77. if success and purchased then
  78. return Enum.ProductPurchaseDecision.PurchaseGranted
  79. elseif not success then
  80. error("Data store error:" .. errorMessage)
  81. end
  82. local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
  83. if not player then
  84. return Enum.ProductPurchaseDecision.NotProcessedYet
  85. end
  86. local handler = productFunctions[receiptInfo.ProductId]
  87.  
  88. local success, result = pcall(handler, receiptInfo, player)
  89. if not success or not result then
  90. warn("Error occurred while processing a product purchase")
  91. print("\nProductId:", receiptInfo.ProductId)
  92. print("\nPlayer:", player)
  93. return Enum.ProductPurchaseDecision.NotProcessedYet
  94. end
  95.  
  96. local success, errorMessage = pcall(function()
  97. purchaseHistoryStore:SetAsync(playerProductKey, true)
  98. end)
  99. if not success then
  100. error("Cannot save purchase data: " .. errorMessage)
  101. end
  102.  
  103. return Enum.ProductPurchaseDecision.PurchaseGranted
  104. end
  105. MarketplaceService.ProcessReceipt = processReceipt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement