Advertisement
Guest User

script 2 btw

a guest
Feb 20th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. local currencyName = "Money"
  2. local currencyName2 = "Skills"
  3. local DataStore = game:GetService("DataStoreService"):GetDataStore("UC")
  4.  
  5. game.Players.PlayerAdded:Connect(function(player)
  6.  
  7. local folder = Instance.new("Folder")
  8. folder.Name = "leaderstats"
  9. folder.Parent = player
  10.  
  11. local currency = Instance.new("IntValue")
  12. currency.Name = currencyName
  13. currency.Parent = folder
  14.  
  15. local currency2 = Instance.new("IntValue")
  16. currency2.Name = currencyName2
  17. currency2.Parent = folder
  18.  
  19. local ID = currencyName.."-"..player.UserId
  20. local savedata = nil
  21.  
  22. pcall(function()
  23. savedData = DataStore:GetAsync(ID)
  24. end)
  25.  
  26. if savedData ~= nil then
  27. currency.Value = savedData
  28. currency2.Value = savedData
  29. print("Data loaded")
  30. else
  31. --New player
  32. currency.Value = 0 -----^ How much you began with
  33. currency2.Value = 15
  34. print("New player to the game")
  35. end
  36.  
  37.  
  38. end)
  39.  
  40. game.Players.PlayerRemoving:Connect(function(player)
  41. local ID = currencyName.."-"..player.UserId
  42. DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
  43. end)
  44.  
  45. game:BindToClose(function()
  46.  
  47. --When Game is ready to shutdown
  48.  
  49. for i, player in pairs(game.Players:GetPlayers()) do
  50. if player then
  51. player:Kick("This Game is Shutting down for saving data and adding updates plz rejoin :D --Fnaf united Dev team CrystalFox123YT")
  52. end
  53. end
  54.  
  55. wait(5)
  56.  
  57. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement