Advertisement
Sungmingamerpro13

My New Leaderboard Story Game (Main)

Jun 24th, 2023 (edited)
1,223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 4.87 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. local SaveMoney = game:GetService("DataStoreService"):GetDataStore("Money")
  7.  
  8. local VIPGamepassId = 3269738970
  9. game.Players.PlayerAdded:Connect(function(player)
  10.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then
  11.         local Folder = Instance.new("Folder",player)
  12.         Folder.Name = "leaderstats"
  13.  
  14.         local Currency = Instance.new("NumberValue",Folder)
  15.         Currency.Name = game.ReplicatedStorage.Tags.RoundsValue.Value
  16.         Currency.Value = SaveCurrency2:GetAsync(player.UserId) or 0
  17.  
  18.         local Currency2 = Instance.new("NumberValue",Folder)
  19.         Currency2.Name = game.ReplicatedStorage.Tags.WinsValue.Value
  20.         Currency2.Value = SaveCurrency:GetAsync(player.UserId) or 0
  21.  
  22.         local previousData = SaveCurrency3:GetAsync(player.UserId)
  23.         local Coins
  24.  
  25.         if previousData ~= nil then
  26.             Coins = previousData
  27.         else
  28.             Coins = 0
  29.             SaveCurrency3:SetAsync(player.UserId, 0)
  30.         end
  31.  
  32.         local CoinsValue = Instance.new("NumberValue", player)
  33.         CoinsValue.Name = "Coins"
  34.         CoinsValue.Value = Coins
  35.  
  36.         local val1 = Instance.new("StringValue",player)
  37.         val1.Name = 'GotPet'
  38.         val1.Value = ''
  39.  
  40.         local val2 = Instance.new("StringValue",player)
  41.         val2.Name = 'OpenValue'
  42.         val2.Value = ''
  43.  
  44.         if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepassId) then
  45.             player.Coins.Value = player.Coins.Value * 2
  46.         end
  47.     end
  48. end)
  49.  
  50. game.Players.PlayerRemoving:Connect(function(player)
  51.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then  
  52.         SaveCurrency:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.WinsValue.Value].Value)
  53.         SaveCurrency2:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.RoundsValue.Value].Value)
  54.     end
  55. end)
  56.  
  57. game:BindToClose(function()
  58.     print("STOPPED!")
  59.  
  60.     for i,player in pairs(game.Players:GetPlayers()) do
  61.         local value = player.Coins.Value
  62.         SaveCurrency3:SetAsync(player.UserId, value)
  63.         print("Saved data for "..player.Name)
  64.     end
  65. end)
  66.  
  67. game.Players.PlayerRemoving:Connect(function(player)
  68.     local value = player.Coins.Value
  69.  
  70.     if value ~= nil then
  71.         print("Found data to save for "..player.Name.."!")
  72.         SaveCurrency3:SetAsync(player.UserId, value)
  73.         print("Saved data for "..player.Name)
  74.     else
  75.         print("Did not manage to find data to save for "..player.Name.."!")
  76.     end
  77. end)
  78.  
  79. game.Players.PlayerAdded:Connect(function(player)
  80.     local previousData2 = SaveRevives:GetAsync(player.UserId)
  81.     local Lives
  82.  
  83.     if previousData2 ~= nil then
  84.         Lives = previousData2
  85.     else
  86.         Lives = 0
  87.         SaveRevives:SetAsync(player.UserId, 0)
  88.     end
  89.  
  90.     local ExtraLivesValue = Instance.new("NumberValue", player)
  91.     ExtraLivesValue.Name = "Lives"
  92.     ExtraLivesValue.Value = Lives
  93. end)
  94.  
  95. game:BindToClose(function()
  96.     print("STOPPED!")
  97.  
  98.     for i, player in pairs(game.Players:GetPlayers()) do
  99.         local value2 = player.Lives.Value
  100.         SaveRevives:SetAsync(player.UserId, value2)
  101.     end
  102. end)
  103.  
  104. game.Players.PlayerRemoving:Connect(function(player)
  105.     local value2 = player.Money.Value
  106.  
  107.     if value2 ~= nil then
  108.         print("Found data to save for "..player.Name.."!")
  109.         SaveRevives:SetAsync(player.UserId, value2)
  110.         print("Saved data for "..player.Name)
  111.     else
  112.         print("Did not manage to find data to save for "..player.Name.."!")
  113.     end
  114. end)
  115.  
  116. game.Players.PlayerAdded:Connect(function(player)
  117.     local previousData2 = SaveMoney:GetAsync(player.UserId)
  118.     local Money
  119.  
  120.     if previousData2 ~= nil then
  121.         Money = previousData2
  122.     else
  123.         Money = 0
  124.         SaveRevives:SetAsync(player.UserId, 0)
  125.     end
  126.  
  127.     local MoneyValue = Instance.new("NumberValue", player)
  128.     MoneyValue.Name = "Money"
  129.     MoneyValue.Value = Money
  130. end)
  131.  
  132. game:BindToClose(function()
  133.     print("STOPPED!")
  134.  
  135.     for i, player in pairs(game.Players:GetPlayers()) do
  136.         local value2 = player.Money.Value
  137.         SaveMoney:SetAsync(player.UserId, value2)
  138.     end
  139. end)
  140.  
  141. game.Players.PlayerRemoving:Connect(function(player)
  142.     local value2 = player.Money.Value
  143.  
  144.     if value2 ~= nil then
  145.         print("Found data to save for "..player.Name.."!")
  146.         SaveMoney:SetAsync(player.UserId, value2)
  147.         print("Saved data for "..player.Name)
  148.     else
  149.         print("Did not manage to find data to save for "..player.Name.."!")
  150.     end
  151. end)
  152.  
  153. game.Players.PlayerAdded:connect(function(player)
  154.     player.CharacterAdded:connect(function(char)
  155.  
  156.         char.Humanoid.Died:connect(function()
  157.             SaveCurrency2:SetAsync(player.UserId, player.leaderstats.Rounds.Value)
  158.             SaveRevives:SetAsync(player.UserId, player.Lives.Value)
  159.             player.leaderstats.Rounds.Value = player.leaderstats.Rounds.Value + 1
  160.             player.Lives.Value = player.Lives.Value - 1
  161.         end)
  162.     end)
  163. end)
  164.  
  165.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement