Advertisement
Sungmingamerpro13

My Sister DataStoreService STORY GAME Lobby

Dec 14th, 2022 (edited)
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.77 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.  
  6. local VIPGamepassId = 26362066
  7. game.Players.PlayerAdded:Connect(function(player)
  8.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then
  9.         local Folder = Instance.new("Folder",player)
  10.         Folder.Name = "leaderstats"
  11.  
  12.         local Currency = Instance.new("NumberValue",Folder)
  13.         Currency.Name = game.ReplicatedStorage.Tags.WinsValue.Value
  14.         Currency.Value = SaveCurrency:GetAsync(player.UserId) or 0
  15.  
  16.         local Currency2 = Instance.new("NumberValue",Folder)
  17.         Currency2.Name = game.ReplicatedStorage.Tags.RoundsValue.Value
  18.         Currency2.Value = SaveCurrency2:GetAsync(player.UserId) or 0
  19.  
  20.         local previousData = SaveCurrency3:GetAsync(player.UserId)
  21.         local Coins
  22.  
  23.         if previousData ~= nil then
  24.             Coins = previousData
  25.         else
  26.             Coins = 0
  27.             SaveCurrency3:SetAsync(player.UserId, 0)
  28.         end
  29.  
  30.         local CoinsValue = Instance.new("NumberValue", player)
  31.         CoinsValue.Name = "Coins"
  32.         CoinsValue.Value = Coins
  33.  
  34.         local val1 = Instance.new("StringValue",player)
  35.         val1.Name = 'GotPet'
  36.         val1.Value = ''
  37.  
  38.         local val2 = Instance.new("StringValue",player)
  39.         val2.Name = 'OpenValue'
  40.         val2.Value = ''
  41.  
  42.         if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepassId) then
  43.             player.Coins.Value = player.Coins.Value * 2
  44.         end
  45.     end
  46. end)
  47.  
  48. game.Players.PlayerRemoving:Connect(function(player)
  49.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then  
  50.         SaveCurrency:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.WinsValue.Value].Value)
  51.         SaveCurrency2:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.RoundsValue.Value].Value)
  52.     end
  53. end)
  54.  
  55. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  56.     print("STOPPED!")
  57.  
  58.     for i,player in pairs(game.Players:GetPlayers()) do
  59.         local value = player.Coins.Value
  60.         SaveCurrency3:SetAsync(player.UserId, value)
  61.         print("Saved data for "..player.Name)
  62.     end
  63. end)
  64.  
  65. game.Players.PlayerRemoving:Connect(function(player)
  66.     local value = player.Coins.Value
  67.  
  68.     if value ~= nil then
  69.         print("Found data to save for "..player.Name.."!")
  70.         SaveCurrency3:SetAsync(player.UserId, value)
  71.         print("Saved data for "..player.Name)
  72.     else
  73.         print("Did not manage to find data to save for "..player.Name.."!")
  74.     end
  75. end)
  76.  
  77. local teleportData = TeleportService:GetLocalPlayerTeleportData()
  78.  
  79. if teleportData then
  80.     local Player = game.Players:GetPlayerByUserId(teleportData.PlayerName)
  81.     Player.leaderstats.Wins.Value = Player.leaderstats.Wins.Value + 1
  82. end
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement