Advertisement
Sungmingamerpro13

My New Leaderboard Story Game 2 (Main)

Jun 24th, 2023
1,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 3.90 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local SaveCurrency = game:GetService("DataStoreService"):GetDataStore("Wins")
  3. local SaveCurrency2 = game:GetService("DataStoreService"):GetDataStore("Rounds")
  4. local SaveCurrency3 = game:GetService("DataStoreService"):GetDataStore("Coins")
  5. local SaveRevives = game:GetService("DataStoreService"):GetDataStore("Lives")
  6.  
  7. local VIPGamepassId = 3269738970
  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 = SaveCurrency2:GetAsync(player.UserId) or 0
  16.  
  17.         local Currency2 = Instance.new("NumberValue",Folder)
  18.         Currency2.Name = game.ReplicatedStorage.Tags.WinsValue.Value
  19.         Currency2.Value = SaveCurrency: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.         if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepassId) then
  44.             player.Coins.Value = player.Coins.Value * 2
  45.         end
  46.     end
  47. end)
  48.  
  49. game.Players.PlayerRemoving:Connect(function(player)
  50.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then  
  51.         SaveCurrency:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.WinsValue.Value].Value)
  52.         SaveCurrency2:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.RoundsValue.Value].Value)
  53.     end
  54. end)
  55.  
  56. game:BindToClose(function()
  57.     print("STOPPED!")
  58.  
  59.     for i,player in pairs(game.Players:GetPlayers()) do
  60.         local value = player.Coins.Value
  61.         SaveCurrency3:SetAsync(player.UserId, value)
  62.         print("Saved data for "..player.Name)
  63.     end
  64. end)
  65.  
  66. game.Players.PlayerRemoving:Connect(function(player)
  67.     local value = player.Coins.Value
  68.  
  69.     if value ~= nil then
  70.         print("Found data to save for "..player.Name.."!")
  71.         SaveCurrency3:SetAsync(player.UserId, value)
  72.         print("Saved data for "..player.Name)
  73.     else
  74.         print("Did not manage to find data to save for "..player.Name.."!")
  75.     end
  76. end)
  77.  
  78. game.Players.PlayerAdded:Connect(function(player)
  79.     local previousData2 = SaveRevives:GetAsync(player.UserId)
  80.     local Lives
  81.  
  82.     if previousData2 ~= nil then
  83.         Lives = previousData2
  84.     else
  85.         Lives = 0
  86.         SaveRevives:SetAsync(player.UserId, 0)
  87.     end
  88.  
  89.     local ExtraLivesValue = Instance.new("NumberValue", player)
  90.     ExtraLivesValue.Name = "Lives"
  91.     ExtraLivesValue.Value = Lives
  92. end)
  93.  
  94. game:BindToClose(function()
  95.     print("STOPPED!")
  96.  
  97.     for i, player in pairs(game.Players:GetPlayers()) do
  98.         local value2 = player.Lives.Value
  99.         SaveRevives:SetAsync(player.UserId, value2)
  100.     end
  101. end)
  102.  
  103. game.Players.PlayerRemoving:Connect(function(player)
  104.     local value2 = player.Lives.Value
  105.  
  106.     if value2 ~= nil then
  107.         print("Found data to save for "..player.Name.."!")
  108.         SaveRevives:SetAsync(player.UserId, value2)
  109.         print("Saved data for "..player.Name)
  110.     else
  111.         print("Did not manage to find data to save for "..player.Name.."!")
  112.     end
  113. end)
  114.  
  115. game.Players.PlayerAdded:connect(function(player)
  116.     player.CharacterAdded:connect(function(char)
  117.  
  118.         char.Humanoid.Died:connect(function()
  119.             SaveCurrency2:SetAsync(player.UserId, player.leaderstats.Rounds.Value)
  120.             SaveRevives:SetAsync(player.UserId, player.Lives.Value)
  121.             player.leaderstats.Rounds.Value = player.leaderstats.Rounds.Value + 1
  122.             player.Lives.Value = player.Lives.Value - 1
  123.         end)
  124.     end)
  125. end)
  126.  
  127.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement