Advertisement
Sungmingamerpro13

My New Leaderstats Main Story Game

Mar 10th, 2023
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 3.87 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local SaveCurrency = game:GetService("DataStoreService"):GetDataStore("Rounds")
  3. local SaveCurrency2 = game:GetService("DataStoreService"):GetDataStore("Wins")
  4. local SaveCurrency3 = game:GetService("DataStoreService"):GetDataStore("Coins")
  5. local SaveExtraLives = game:GetService("DataStoreService"):GetDataStore("Lives")
  6.  
  7. local VIPGamepassId = 64418164
  8. game.Players.PlayerAdded:Connect(function(player)
  9.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then
  10.         local Folder = Instance.new("Folder",player)
  11.         Folder.Name = "leaderstats"
  12.  
  13.         local Currency = Instance.new("NumberValue",Folder)
  14.         Currency.Name = game.ReplicatedStorage.Tags.RoundsValue.Value
  15.         Currency.Value = SaveCurrency:GetAsync(player.UserId) or 0
  16.  
  17.         local Currency2 = Instance.new("NumberValue",Folder)
  18.         Currency2.Name = game.ReplicatedStorage.Tags.WinsValue.Value
  19.         Currency2.Value = SaveCurrency2:GetAsync(player.UserId) or 0
  20.  
  21.         local previousData = SaveCurrency3:GetAsync(player.UserId)
  22.         local Coins
  23.  
  24.         if previousData ~= nil then
  25.             Coins = previousData
  26.         else
  27.             Coins = 0
  28.             SaveCurrency3:SetAsync(player.UserId, 0)
  29.         end
  30.  
  31.         local CoinsValue = Instance.new("NumberValue", player)
  32.         CoinsValue.Name = "Coins"
  33.         CoinsValue.Value = Coins
  34.  
  35.         local val1 = Instance.new("StringValue",player)
  36.         val1.Name = 'GotPet'
  37.         val1.Value = ''
  38.  
  39.         local val2 = Instance.new("StringValue",player)
  40.         val2.Name = 'OpenValue'
  41.         val2.Value = ''
  42.  
  43.         local previousData2 = SaveExtraLives:GetAsync(player.UserId)
  44.         local Lives
  45.  
  46.         if previousData2 ~= nil then
  47.             Lives = previousData2
  48.         else
  49.             Lives = 0
  50.             SaveExtraLives:SetAsync(player.UserId, 0)
  51.         end
  52.  
  53.         local ExtraLivesValue = Instance.new("NumberValue", player)
  54.         ExtraLivesValue.Name = "Lives"
  55.         ExtraLivesValue.Value = Lives
  56.  
  57.         if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepassId) then
  58.             player.Coins.Value = player.Coins.Value * 2
  59.         end
  60.     end
  61. end)
  62.  
  63. game.Players.PlayerRemoving:Connect(function(player)
  64.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then  
  65.         SaveCurrency:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.RoundsValue.Value].Value)
  66.         SaveCurrency2:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.WinsValue.Value].Value)
  67.     end
  68. end)
  69.  
  70. game:BindToClose(function()
  71.     print("STOPPED!")
  72.  
  73.     for i,player in pairs(game.Players:GetPlayers()) do
  74.         local value = player.Coins.Value
  75.         SaveCurrency3:SetAsync(player.UserId, value)
  76.         print("Saved data for "..player.Name)
  77.     end
  78. end)
  79.  
  80. game.Players.PlayerRemoving:Connect(function(player)
  81.     local value = player.Coins.Value
  82.  
  83.     if value ~= nil then
  84.         print("Found data to save for "..player.Name.."!")
  85.         SaveCurrency3:SetAsync(player.UserId, value)
  86.         print("Saved data for "..player.Name)
  87.     else
  88.         print("Did not manage to find data to save for "..player.Name.."!")
  89.     end
  90. end)
  91.  
  92. game:BindToClose(function()
  93.     print("STOPPED!")
  94.  
  95.     for i, player in pairs(game.Players:GetPlayers()) do
  96.         local value2 = player.Lives.Value
  97.         SaveExtraLives:SetAsync(player.UserId, value2)
  98.     end
  99. end)
  100.  
  101. game.Players.PlayerRemoving:Connect(function(player)
  102.     local value2 = player.Lives.Value
  103.  
  104.     if value2 ~= nil then
  105.         print("Found data to save for "..player.Name.."!")
  106.         SaveExtraLives:SetAsync(player.UserId, value2)
  107.         print("Saved data for "..player.Name)
  108.     else
  109.         print("Did not manage to find data to save for "..player.Name.."!")
  110.     end
  111. end)
  112.  
  113. game.Players.PlayerAdded:connect(function(player)
  114.     player.CharacterAdded:connect(function(char)
  115.  
  116.         char.Humanoid.Died:connect(function()
  117.             SaveCurrency:SetAsync(player.UserId, player.leaderstats.Rounds.Value)
  118.             SaveExtraLives:SetAsync(player.UserId, player.Lives.Value)
  119.             player.Lives.Value = player.Lives.Value - 1
  120.             player.leaderstats.Rounds.Value = player.leaderstats.Rounds.Value + 1
  121.         end)
  122.     end)
  123. end)
  124.  
  125.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement