Advertisement
Sungmingamerpro13

New Wins,Coins Main Game

Jan 31st, 2023
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.69 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.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement