Advertisement
Guest User

Untitled

a guest
Nov 27th, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. local skipId = 106323481
  2.  
  3. local dataStoreService = game:GetService("DataStoreService")
  4. local mps = game:GetService("MarketplaceService")
  5.  
  6. local stageDataStore = dataStoreService:GetDataStore("stageStore")
  7.  
  8. game.Players.PlayerAdded:Connect(function(plr)
  9.    
  10.     local leaderstats = Instance.new("Folder")
  11.     leaderstats.Parent = plr
  12.     leaderstats.Name = "leaderstats"
  13.    
  14.     local stage = Instance.new("IntValue")
  15.     stage.Parent = leaderstats
  16.     stage.Name = "Stage"
  17.     stage.Value = 0
  18.    
  19.     local data
  20.    
  21.     local success, errormessage = pcall(function()
  22.         data = stageDataStore:GetAsync(plr.UserId.. "-Stage")
  23.     end)
  24.    
  25.     if success then
  26.         print(tostring(plr).. "'s data was successfully retrieved.")
  27.         stage.Value = data
  28.        
  29.         if stage.Value == 0 then
  30.             stage.Value = 0
  31.             repeat wait() until plr:FindFirstChild("TempStage")
  32.             plr.TempStage.Value = 0
  33.             plr:LoadCharacter()
  34.         end
  35.     elseif errormessage then
  36.         warn(tostring(plr).. "'s data had an issue loading.")
  37.         warn(errormessage)
  38.         stage.Value = 0
  39.     end
  40. end)
  41.  
  42. game.Players.PlayerRemoving:Connect(function(plr)
  43.     print(tostring(plr).. " is leaving the game.")
  44.    
  45.     local success, errormessage = pcall(function()
  46.         stageDataStore:SetAsync(plr.UserId.. "-Stage", plr.leaderstats.Stage.Value)
  47.     end)
  48.    
  49.     if success then
  50.         print(tostring(plr).. "'s data was successfully saved.")
  51.     elseif errormessage then
  52.         warn(tostring(plr).. "'s data had an issue saving.")
  53.         warn(errormessage)
  54.     end
  55. end)
  56.  
  57. mps.ProcessReceipt = function(info)
  58.     local plr = game.Players:GetPlayerByUserId(info.PlayerId)
  59.     if info.ProductId == skipId then
  60.         plr.leaderstats.Stage.Value += 1
  61.         plr:LoadCharacter()
  62.     end
  63.     return Enum.ProductPurchaseDecision.PurchaseGranted
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement