Advertisement
drakon-firestone

LoadData

May 31st, 2023
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. local function LoadData(player)
  2. for i, v in pairs(playerData:GetChildren()) do
  3. v:Clone().Parent = player
  4. end
  5.  
  6. local data
  7.  
  8. local success, errorMsg = pcall(function()
  9.  
  10. data = dataStore:GetAsync(player.UserId .. key)
  11.  
  12. for key, folder in pairs(data) do
  13. if key == "leaderstats" then
  14. for item, amount in pairs(folder) do
  15. if item == "Coins" then
  16. player.leaderstats.Coins.Value = amount
  17. elseif item == "Diamonds" then
  18. player.leaderstats.Diamonds.Value = amount
  19. end
  20. end
  21. end
  22.  
  23. if key == "Areas" then
  24. for item, _ in pairs(folder) do
  25. if not player.Areas:FindFirstChild(item) then
  26. local value = Instance.new("StringValue", player.Areas)
  27. value.Name = item
  28. area:FireClient(player, workspace.Areas[value.Name].Barrier)
  29. end
  30. end
  31. end
  32.  
  33. if key == "Pets" then
  34. for id, petName in pairs(folder) do
  35. local pet = Instance.new("StringValue", player.Pets)
  36. pet.Name = petName
  37. pet.Value = id
  38. createTemplate:FireClient(player, petName, id)
  39. end
  40. end
  41.  
  42.  
  43. end
  44. print("Loaded data")
  45. print(data)
  46. end)
  47.  
  48. if not success then
  49. warn(errorMsg)
  50. wait(5)
  51. LoadData(player)
  52. end
  53.  
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement