Advertisement
Jackthehunter25

Untitled

Nov 27th, 2020 (edited)
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 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. local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
  77. print("hi1")
  78. if success then game.ReplicatedStorage.Purchased:FireClient(player)
  79. print("hi")
  80. return Enum.ProductPurchaseDecision.PurchaseGranted
  81. elseif not success then
  82. error("Data store error:" .. errorMessage)
  83. end
  84.  
  85. if not player then
  86. return Enum.ProductPurchaseDecision.NotProcessedYet
  87. end
  88. local handler = productFunctions[receiptInfo.ProductId]
  89.  
  90. local success, result = pcall(handler, receiptInfo, player)
  91. if not success or not result then
  92. warn("Error occurred while processing a product purchase")
  93. print("\nProductId:", receiptInfo.ProductId)
  94. print("\nPlayer:", player)
  95. return Enum.ProductPurchaseDecision.NotProcessedYet
  96. end
  97.  
  98. local success, errorMessage = pcall(function()
  99. purchaseHistoryStore:SetAsync(playerProductKey, true)
  100. end)
  101. if not success then
  102. error("Cannot save purchase data: " .. errorMessage)
  103. end
  104.  
  105. return Enum.ProductPurchaseDecision.PurchaseGranted
  106. end
  107. MarketplaceService.ProcessReceipt = processReceipt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement