Advertisement
Guest User

Untitled

a guest
Mar 19th, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. local MarketplaceService = game:GetService("MarketplaceService")
  2.  
  3. local Players = game:GetService("Players")
  4. local dataStoreService = game:GetService("DataStoreService")
  5. local mainStore = dataStoreService:GetDataStore("MainStore")
  6. local httpService = game:GetService("HttpService")
  7. local productFunctions = {}
  8.  
  9.  
  10. function saveData (plr)
  11. repeat
  12. task.wait();
  13. local success, errormessage = pcall(function()
  14. local data = {plr.leaderstats.Wins.Value, plr.mainData.Coins.Value, plr.mainData.XP.Value}
  15. data = httpService:JSONEncode(data)
  16. mainStore:SetAsync(plr.UserId,data)
  17. end)
  18.  
  19.  
  20. if success then
  21. print("Successfully saved "..tostring(plr.Name).."'s data.")
  22. end
  23. until success;
  24. end
  25.  
  26.  
  27. productFunctions[my id here] = function(receipt, player)
  28. player.mainData.Coins.Value = player.mainData.Coins.Value + 100
  29. local tempStage = (100 - 10)/3 + 1;
  30. local xpCalculation = ((tempStage-1)*2.5)+10
  31. player.mainData.XP.Value += xpCalculation
  32. saveData(player);
  33. return true;
  34. end
  35.  
  36. productFunctions[id here] = function(receipt, player)
  37. player.mainData.Coins.Value = player.mainData.Coins.Value + 1000
  38. local tempStage = (1000 - 10)/3 + 1;
  39. local xpCalculation = ((tempStage-1)*2.5)+10
  40. player.mainData.XP.Value += xpCalculation
  41. saveData(player);
  42. return true;
  43. end
  44.  
  45. productFunctions[id here] = function(receipt, player)
  46. player.mainData.Coins.Value = player.mainData.Coins.Value + 10000
  47. local tempStage = (10000 - 10)/3 + 1;
  48. local xpCalculation = ((tempStage-1)*2.5)+10
  49. player.mainData.XP.Value += xpCalculation
  50. saveData(player);
  51. return true;
  52. end
  53.  
  54.  
  55.  
  56.  
  57.  
  58. local function processReceipt(receiptInfo)
  59. local userId = receiptInfo.PlayerId
  60. local productId = receiptInfo.ProductId
  61.  
  62. local player = Players:GetPlayerByUserId(userId)
  63. if player then
  64. -- Get the handler function associated with the developer product ID and attempt to run it
  65. local handler = productFunctions[productId]
  66. local success, result = pcall(handler, receiptInfo, player)
  67. if success then
  68. -- The player has received their benefits!
  69. -- return PurchaseGranted to confirm the transaction.
  70. return Enum.ProductPurchaseDecision.PurchaseGranted
  71. else
  72. warn("Failed to process receipt:", receiptInfo, result)
  73. end
  74. end
  75.  
  76. -- the player's benefits couldn't be awarded.
  77. -- return NotProcessedYet to try again next time the player joins.
  78. return Enum.ProductPurchaseDecision.NotProcessedYet
  79. end
  80.  
  81. -- Set the callback; this can only be done once by one script on the server!
  82. MarketplaceService.ProcessReceipt = processReceipt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement