Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MarketplaceService = game:GetService("MarketplaceService")
- local DataStoreService = game:GetService("DataStoreService")
- local Players = game:GetService("Players")
- local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
- local productFunctions = {}
- productFunctions[1088662111] = function(receipt, player)
- local stats = player:FindFirstChild("leaderstats")
- local Coins = stats and stats:FindFirstChild("Coins")
- if Coins then
- Coins.Value = Coins.Value + 100
- return true
- end
- end
- productFunctions[1118688140] = function(receipt, player)
- local stats = player:FindFirstChild("leaderstats")
- local Coins = stats and stats:FindFirstChild("Coins")
- if Coins then
- Coins.Value = Coins.Value + 500
- return true
- end
- end
- productFunctions[1118688247] = function(receipt, player)
- local stats = player:FindFirstChild("leaderstats")
- local Coins = stats and stats:FindFirstChild("Coins")
- if Coins then
- Coins.Value = Coins.Value + 1250
- return true
- end
- end
- productFunctions[1118688441] = function(receipt, player)
- local stats = player:FindFirstChild("leaderstats")
- local Coins = stats and stats:FindFirstChild("Coins")
- if Coins then
- Coins.Value = Coins.Value + 2000
- return true
- end
- end
- productFunctions[1118688565] = function(receipt, player)
- local stats = player:FindFirstChild("leaderstats")
- local Coins = stats and stats:FindFirstChild("Coins")
- if Coins then
- Coins.Value = Coins.Value + 2800
- return true
- end
- end
- productFunctions[1118688866] = function(receipt, player)
- local stats = player:FindFirstChild("leaderstats")
- local Coins = stats and stats:FindFirstChild("Coins")
- if Coins then
- Coins.Value = Coins.Value + 4000
- 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)
- local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
- print("hi1")
- if success then game.ReplicatedStorage.Purchased:FireClient(player)
- print("hi")
- return Enum.ProductPurchaseDecision.PurchaseGranted
- elseif not success then
- error("Data store error:" .. errorMessage)
- end
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement