Advertisement
Sungmingamerpro13

New Story Game DataStore (Lobby)

Dec 2nd, 2023 (edited)
916
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 3.45 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local RoundsDataStore = game:GetService("DataStoreService"):GetDataStore("Rounds")
  3. local WinsDataStore = game:GetService("DataStoreService"):GetDataStore("Wins")
  4. local AddRoundsDataStore = game:GetService("DataStoreService"):GetDataStore("AddRounds")
  5. local AddWinsDataStore = game:GetService("DataStoreService"):GetDataStore("AddWins")
  6. local CoinsDataStore = game:GetService("DataStoreService"):GetDataStore("Coins")
  7. local LevelsDataStore = game:GetService("DataStoreService"):GetDataStore("Level")
  8. local ExpDataStore = game:GetService("DataStoreService"):GetDataStore("Exp")
  9.  
  10. local VIPGamepass = (267214996)
  11.  
  12. game.Players.PlayerAdded:Connect(function(player)
  13.    
  14.     local Folder = Instance.new("Folder", player)
  15.     Folder.Name = "leaderstats"
  16.    
  17.     local Rounds = Instance.new("NumberValue", Folder)
  18.     Rounds.Name = "Rounds"
  19.     Rounds.Value = RoundsDataStore:GetAsync(player.UserId) or 0
  20.    
  21.     local Wins = Instance.new("NumberValue", Folder)
  22.     Wins.Name = "Wins"
  23.     Wins.Value = WinsDataStore:GetAsync(player.UserId) or 0
  24.    
  25.     local AddRounds = Instance.new("NumberValue", player)
  26.     AddRounds.Name = "AddRounds"
  27.     AddRounds.Value = AddRoundsDataStore:GetAsync(player.UserId) or 0
  28.  
  29.     local AddWins = Instance.new("NumberValue", player)
  30.     AddWins.Name = "AddWins"
  31.     AddWins.Value = AddWinsDataStore:GetAsync(player.UserId) or 0
  32.    
  33.     local Coins = Instance.new("NumberValue", player)
  34.     Coins.Name = "Coins"
  35.     Coins.Value = CoinsDataStore:GetAsync(player.UserId) or 0
  36.    
  37.     local Levels = Instance.new("NumberValue", Folder)
  38.     Levels.Name = "Levels"
  39.     Levels.Value = LevelsDataStore:GetAsync(player.UserId) or 1
  40.    
  41.     local Exp = Instance.new("NumberValue", Folder)
  42.     Exp.Name = "Exp"
  43.     Exp.Value = ExpDataStore:GetAsync(player.UserId) or 0
  44.    
  45.     while wait() do
  46.         if Exp.Value >= (100 * (Levels.Value + 1)) then
  47.             Levels.Value = Levels.Value + 1
  48.             Exp.Value = 0
  49.         end
  50.     end
  51.    
  52.     if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepass) then
  53.         player.Coins.Value = player.Coins.Value * 2
  54.     end
  55.    
  56.     if player.AddWins.Value >= 1 then
  57.         player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
  58.     end
  59.    
  60.     if player.AddRounds.Value >= 1 then
  61.         player.leaderstats.Rounds.Value = player.leaderstats.Rounds.Value + 1
  62.     end
  63.    
  64. end)
  65.  
  66. game.Players.PlayerRemoving:Connect(function(player)
  67.     RoundsDataStore:SetAsync(player.UserId, player.leaderstats.Rounds.Value)
  68.     WinsDataStore:SetAsync(player.UserId, player.leaderstats.Wins.Value)
  69.     AddRoundsDataStore:SetAsync(player.UserId, player.AddRounds.Value)
  70.     AddWinsDataStore:SetAsync(player.UserId, player.AddWins.Value)
  71.     CoinsDataStore:SetAsync(player.UserId, player.Coins.Value)
  72.     LevelsDataStore:SetAsync(player.UserId, player.leaderstats.Levels.Value)
  73.     ExpDataStore:SetAsync(player.UserId, player.leaderstats.Exp.Value)
  74. end)
  75.  
  76. game:BindToClose(function()
  77.     print("STOPPED!")
  78.  
  79.     for i,player in pairs(game.Players:GetPlayers()) do
  80.         RoundsDataStore:SetAsync(player.UserId, player.leaderstats.Rounds.Value)
  81.         WinsDataStore:SetAsync(player.UserId, player.leaderstats.Wins.Value)
  82.         AddRoundsDataStore:SetAsync(player.UserId, player.AddRounds.Value)
  83.         AddWinsDataStore:SetAsync(player.UserId, player.AddWins.Value)
  84.         CoinsDataStore:SetAsync(player.UserId, player.Coins.Value)
  85.         LevelsDataStore:SetAsync(player.UserId, player.leaderstats.Levels.Value)
  86.         ExpDataStore:SetAsync(player.UserId, player.leaderstats.Exp.Value)
  87.         print("Saved data for "..player.Name)
  88.     end
  89. end)
  90.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement