Advertisement
Sungmingamerpro13

Technogamerz Datastore Main Game (STORY GAME)

Aug 13th, 2022
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 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. local SaveCurrency4 = game:GetService("DataStoreService"):GetDataStore("Money")
  6.  
  7. local VIPGamepassId = 27379554
  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 previousData2 = SaveCurrency4:GetAsync(player.UserId)
  23. local Coins
  24. local Money
  25.  
  26. if previousData ~= nil then
  27. Coins = previousData
  28. else
  29. Coins = 0
  30. SaveCurrency3:SetAsync(player.UserId, 0)
  31. end
  32.  
  33. if previousData2 ~= nil then
  34. Money = previousData2
  35. else
  36. Money = 0
  37. SaveCurrency4:SetAsync(player.UserId, 0)
  38. end
  39.  
  40. local CoinsValue = Instance.new("NumberValue", player)
  41. CoinsValue.Name = "Coins"
  42. CoinsValue.Value = Coins
  43.  
  44. local val1 = Instance.new("StringValue",player)
  45. val1.Name = 'GotPet'
  46. val1.Value = ''
  47.  
  48. local val2 = Instance.new("StringValue",player)
  49. val2.Name = 'OpenValue'
  50. val2.Value = ''
  51.  
  52. local MoneyValue = Instance.new("NumberValue", player)
  53. MoneyValue.Name = "Money"
  54. MoneyValue.Value = Money
  55.  
  56. if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepassId) then
  57. player.Coins.Value = player.Coins.Value * 2
  58. player.Money.Value = player.Money.Value * 2
  59. end
  60. end
  61. end)
  62.  
  63. game.Players.PlayerRemoving:Connect(function(player)
  64. if game.ReplicatedStorage.Tags.Leaderstats.Value == true then
  65. SaveCurrency:SetAsync(player.UserId,player.Leaderstats[game.ReplicatedStorage.Tags.WinsValue.Value].Value)
  66. SaveCurrency2:SetAsync(player.UserId,player.Leaderstats[game.ReplicatedStorage.Tags.RoundsValue.Value].Value)
  67. end
  68. end)
  69.  
  70. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  71. print("STOPPED!")
  72.  
  73. for i,player in pairs(game.Players:GetPlayers()) do
  74. local value = player.Coins.Value
  75. SaveCurrency3:SetAsync(player.UserId, value)
  76. print("Saved data for "..player.Name)
  77. end
  78. end)
  79.  
  80. game.Players.PlayerRemoving:Connect(function(player)
  81. local value = player.Coins.Value
  82.  
  83. if value ~= nil then
  84. print("Found data to save for "..player.Name.."!")
  85. SaveCurrency3:SetAsync(player.UserId, value)
  86. print("Saved data for "..player.Name)
  87. else
  88. print("Did not manage to find data to save for "..player.Name.."!")
  89. end
  90. end)
  91.  
  92. game.Players.PlayerAdded:connect(function(player)
  93. player.CharacterAdded:connect(function(char)
  94.  
  95. char.Humanoid.Died:connect(function()
  96. SaveCurrency2:SetAsync(player.UserId, player.leaderstats.Rounds.Value)
  97. player.Leaderstats.Rounds.Value = player.Leaderstats.Rounds.Value + 1
  98. end)
  99. end)
  100. end)
  101.  
  102.  
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement