Advertisement
Sungmingamerpro13

Story Game New DataStore Lobby v2

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