Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MarketplaceService = game:GetService("MarketplaceService")
- local Players = game:GetService("Players")
- local dataStoreService = game:GetService("DataStoreService")
- local mainStore = dataStoreService:GetDataStore("MainStore")
- local httpService = game:GetService("HttpService")
- local productFunctions = {}
- function saveData (plr)
- repeat
- task.wait();
- local success, errormessage = pcall(function()
- local data = {plr.leaderstats.Wins.Value, plr.mainData.Coins.Value, plr.mainData.XP.Value}
- data = httpService:JSONEncode(data)
- mainStore:SetAsync(plr.UserId,data)
- end)
- if success then
- print("Successfully saved "..tostring(plr.Name).."'s data.")
- end
- until success;
- end
- productFunctions[my id here] = function(receipt, player)
- player.mainData.Coins.Value = player.mainData.Coins.Value + 100
- local tempStage = (100 - 10)/3 + 1;
- local xpCalculation = ((tempStage-1)*2.5)+10
- player.mainData.XP.Value += xpCalculation
- saveData(player);
- return true;
- end
- productFunctions[id here] = function(receipt, player)
- player.mainData.Coins.Value = player.mainData.Coins.Value + 1000
- local tempStage = (1000 - 10)/3 + 1;
- local xpCalculation = ((tempStage-1)*2.5)+10
- player.mainData.XP.Value += xpCalculation
- saveData(player);
- return true;
- end
- productFunctions[id here] = function(receipt, player)
- player.mainData.Coins.Value = player.mainData.Coins.Value + 10000
- local tempStage = (10000 - 10)/3 + 1;
- local xpCalculation = ((tempStage-1)*2.5)+10
- player.mainData.XP.Value += xpCalculation
- saveData(player);
- return true;
- end
- local function processReceipt(receiptInfo)
- local userId = receiptInfo.PlayerId
- local productId = receiptInfo.ProductId
- local player = Players:GetPlayerByUserId(userId)
- if player then
- -- Get the handler function associated with the developer product ID and attempt to run it
- local handler = productFunctions[productId]
- local success, result = pcall(handler, receiptInfo, player)
- if success then
- -- The player has received their benefits!
- -- return PurchaseGranted to confirm the transaction.
- return Enum.ProductPurchaseDecision.PurchaseGranted
- else
- warn("Failed to process receipt:", receiptInfo, result)
- end
- end
- -- the player's benefits couldn't be awarded.
- -- return NotProcessedYet to try again next time the player joins.
- return Enum.ProductPurchaseDecision.NotProcessedYet
- end
- -- Set the callback; this can only be done once by one script on the server!
- MarketplaceService.ProcessReceipt = processReceipt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement