Advertisement
Gomlsauresrex

Untitled

Apr 12th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. --Heres an example for saving and loading data
  2.  
  3. local dss=game:GetService("DataStoreService"):GetDataStore("Lol")
  4.  
  5. function onJoined(player)
  6. local key="user_"..player.UserId
  7. local credits=Instance.new("StringValue", player)
  8. credits.Name="Credits"
  9. credits.Value=dss:GetAsync(key) or 0
  10. end
  11.  
  12. function onLeft(player)
  13. local key="user_"..player.UserId
  14. local success, message=pcall(function()
  15. dss:SetAsync(key, player.Credits.Value)
  16. end)
  17. if success then
  18. print("Saved " .. player.Name .. " data")
  19. else
  20. print("Failed to save " ..player.Name .. " data." ..message)
  21. end
  22. end
  23.  
  24. game.Players.ChildAdded:Connect(function(player) onJoined(player) end)
  25. game.Players.ChildRemoved:Connect(function(player) onLeft(player) end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement