Advertisement
Sungmingamerpro13

New Story Game DataStore (Main)

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