Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. This Datastore won't save I'm getting really frustrated! Please help me!
  2.  
  3. local DS = game:GetService("DataStoreService"):GetDataStore("Levelz")
  4. local StatFile = game:GetService("ServerStorage"):WaitForChild("StatFile")
  5.  
  6. game.Players.PlayerAdded:connect(function(player)
  7. local Key = "Player-"..player.userId
  8.  
  9. local playerfolder = Instance.new("Folder", StatFile)
  10. playerfolder.Name = player.Name
  11.  
  12. local strength = Instance.new("IntValue", playerfolder)
  13. strength.Name = "Strength"
  14.  
  15. local defense = Instance.new("IntValue",playerfolder)
  16. defense.Name = "Defense"
  17.  
  18. local sword = Instance.new("IntValue", playerfolder)
  19. sword.Name = "Sword"
  20.  
  21. local slevel = Instance.new("IntValue", playerfolder)
  22. slevel.Name = "SLevel"
  23.  
  24. local health = Instance.new("IntValue", playerfolder)
  25. health.Name = "Health"
  26.  
  27.  
  28.  
  29. if DS:GetAsync(Key) then
  30. defense.Value = DS:GetAsync(Key)
  31. strength.Value = DS:GetAsync(Key)
  32. sword.Value = DS:GetAsync(Key)
  33. health.Value = DS:GetAsync(Key)
  34. slevel.Value = DS:GetAsync(Key)
  35. end
  36.  
  37. end)
  38.  
  39. game.Players.PlayerRemoving:connect(function(player)
  40. local Key = "Player-"..player.userId
  41. local AllStats = game.ServerStorage.StatFile[player.Name]:GetChildren()
  42. for i = 1, #AllStats do
  43. DS:SetAsync(Key,AllStats[i].Value, AllStats[i].Name)
  44. end
  45.  
  46. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement