Advertisement
Sungmingamerpro13

New Wins,Coins,Donated Lobby Game

Jan 31st, 2023
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 4.15 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local dVersion = 1
  3.  
  4. local VIPGamepass = 0
  5.  
  6. local WinsDataStore = game:GetService("DataStoreService"):GetDataStore('Wins')
  7.  
  8.  
  9. game.Players.PlayerAdded:Connect(function(Player)
  10.  
  11.     local Stats = Instance.new('Folder')
  12.     Stats.Name = 'leaderstats'
  13.     Stats.Parent = Player
  14.  
  15.     local Wins = Instance.new('IntValue')
  16.     Wins.Name = 'Wins'
  17.     Wins.Parent = Stats
  18.  
  19.  
  20.     local Data = WinsDataStore:GetAsync(Player.UserId)
  21.  
  22.  
  23.     if Data then
  24.         for name, value in pairs(Data.Stats) do
  25.             Stats[name].Value = value
  26.         end
  27.  
  28.     end
  29.  
  30.  
  31.  
  32. end)
  33.  
  34. game.Players.PlayerRemoving:Connect(function(Player)
  35.     local SaveData = {Stats = {}}
  36.  
  37.  
  38.  
  39.     for _, stat in pairs(Player.leaderstats:GetChildren()) do
  40.         SaveData.Stats[stat.Name] = stat.Value
  41.     end
  42.  
  43.  
  44.  
  45.  
  46.  
  47.     WinsDataStore:SetAsync(Player.UserId,SaveData)
  48.  
  49.  
  50. end)
  51.  
  52. game:BindToClose(function()
  53.     for _, Player in pairs(game.Players:GetPlayers()) do
  54.         local SaveData = {Stats = {}}
  55.  
  56.  
  57.  
  58.         for _,stat in pairs(Player.leaderstats:GetChildren()) do
  59.             SaveData.Stats[stat.Name] = stat.Value
  60.         end
  61.  
  62.  
  63.  
  64.         WinsDataStore:SetAsync(Player.UserId,SaveData)
  65.  
  66.     end
  67.  
  68.     wait(2)
  69. end)
  70.  
  71. local SaveCoins = game:GetService("DataStoreService"):GetOrderedDataStore("Coins", dVersion)
  72.  
  73. game.Players.PlayerAdded:Connect(function(player)
  74.     local previousData = SaveCoins:GetAsync(player.UserId)
  75.  
  76.     local Coins
  77.  
  78.     if previousData ~= nil then
  79.         Coins = previousData
  80.     else
  81.         Coins = 0
  82.         SaveCoins:SetAsync(player.UserId, 0)
  83.     end
  84.  
  85.     local WinsValue = Instance.new("NumberValue", player)
  86.     WinsValue.Name = "Coins"
  87.     WinsValue.Value = Coins
  88.    
  89.     local val1 = Instance.new("StringValue",player)
  90.     val1.Name = 'GotPet'
  91.     val1.Value = ''
  92.  
  93.     local val2 = Instance.new("StringValue",player)
  94.     val2.Name = 'OpenValue'
  95.     val2.Value = ''
  96.    
  97.     if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepass) then
  98.         player.Coins.Value = player.Coins.Value *2
  99.     end
  100.  
  101. end)
  102.  
  103. game:BindToClose(function()
  104.  
  105.     for i, player in pairs(game.Players:GetPlayers()) do
  106.         local Value = player.Coins.Value
  107.  
  108.         SaveCoins:SetAsync(player.UserId, Value)
  109.     end
  110. end)
  111.  
  112. game.Players.PlayerRemoving:Connect(function(player)
  113.     local Value = player.Coins.Value
  114.  
  115.     if Value ~= nil then
  116.         print("Found data to save for "..player.Name.."!")
  117.         SaveCoins:SetAsync(player.UserId, Value)
  118.         print("Saved data for "..player.Name)
  119.     else
  120.         print("Did not manage to find data to save for "..player.Name.."!")
  121.     end
  122. end)
  123.  
  124. local DonatedDataStore = game:GetService("DataStoreService"):GetDataStore('Donated')
  125.  
  126.  
  127. game.Players.PlayerAdded:Connect(function(Player)
  128.  
  129.     local Stats = Instance.new('Folder')
  130.     Stats.Name = 'leaderstats'
  131.     Stats.Parent = Player
  132.  
  133.     local Donated = Instance.new('IntValue')
  134.     Donated.Name = 'Donated'
  135.     Donated.Parent = Stats
  136.  
  137.  
  138.     local Data = DonatedDataStore:GetAsync(Player.UserId)
  139.  
  140.  
  141.     if Data then
  142.         for name, value in pairs(Data.Stats) do
  143.             Stats[name].Value = value
  144.         end
  145.  
  146.     end
  147.  
  148.  
  149.  
  150. end)
  151.  
  152. game.Players.PlayerRemoving:Connect(function(Player)
  153.     local SaveData = {Stats = {}}
  154.  
  155.  
  156.  
  157.     for _, stat in pairs(Player.leaderstats:GetChildren()) do
  158.         SaveData.Stats[stat.Name] = stat.Value
  159.     end
  160.  
  161.  
  162.  
  163.  
  164.  
  165.     DonatedDataStore:SetAsync(Player.UserId,SaveData)
  166.  
  167.  
  168. end)
  169.  
  170. game:BindToClose(function()
  171.     for _, Player in pairs(game.Players:GetPlayers()) do
  172.         local SaveData = {Stats = {}}
  173.  
  174.  
  175.  
  176.         for _,stat in pairs(Player.leaderstats:GetChildren()) do
  177.             SaveData.Stats[stat.Name] = stat.Value
  178.         end
  179.  
  180.  
  181.  
  182.         DonatedDataStore:SetAsync(Player.UserId,SaveData)
  183.  
  184.     end
  185.  
  186.     wait(2)
  187. end)
  188.  
  189. local TeleportData = TeleportService:GetLocalPlayerTeleportData()
  190.  
  191. if TeleportData then
  192.     local player = game.Players:GetPlayerByUserId(TeleportData.PlayerName)
  193.     player:WaitForChild("leaderstats"):WaitForChild("Wins").Value = player.leaderstats.Wins.Value + 1
  194. end
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement