xmaanzach

DataStore #1

Jan 5th, 2018
4,402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. local DSService = game:GetService('DataStoreService'):GetDataStore('Hamburger223232')
  2. game.Players.PlayerAdded:connect(function(plr)
  3. -- Define variables
  4. local uniquekey = 'id-'..plr.UserId
  5. local leaderstats = Instance.new('IntValue',plr)
  6. local savevalue = Instance.new('IntValue')
  7. leaderstats.Name = 'leaderstats'
  8. savevalue.Parent = leaderstats
  9. savevalue.Name = 'Cash'
  10.  
  11. -- GetAsync
  12. local GetSaved = DSService:GetAsync(uniquekey)
  13. if GetSaved then
  14. savevalue.Value = GetSaved[1]
  15. else
  16. local NumbersForSaving = {savevalue.Value}
  17. DSService:SetAsync(uniquekey,NumbersForSaving)
  18. end
  19. end)
  20.  
  21. game.Players.PlayerRemoving:connect(function(plr)
  22. local uniquekey = 'id-'..plr.UserId
  23. local Savetable = {plr.leaderstats.Cash.Value}
  24. DSService:SetAsync(uniquekey,Savetable)
  25. end)
Advertisement
Add Comment
Please, Sign In to add comment