Advertisement
DragonSploitsYT

Untitled

Jul 20th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local Datastore = game:GetService("DataStoreService"):GetDataStore("PlayerData_3")
  3. local RS = game:GetService("ReplicatedStorage")
  4.  
  5. function getLevel(totalXP)
  6. local Increment = 0
  7. local RequiredXP = 100
  8. for i = 0, RS.Pets.Settings.MaxPetLevel.Value do
  9. RequiredXP = 100 + (25*i)
  10. if totalXP >= (100*i) + Increment then
  11. if i ~= RS.Pets.Settings.MaxPetLevel.Value then
  12. if totalXP < ((100*i) + Increment) + RequiredXP then
  13. return i
  14. end
  15. else
  16. return i
  17. end
  18. end
  19. Increment = Increment+(i*25)
  20. end
  21. end
  22.  
  23. Players.PlayerRemoving:Connect(function(plr)
  24. local Pets = plr.Pets
  25. local Data = plr.Data
  26.  
  27. local PetData = {}
  28. local PlayerData = {}
  29.  
  30. for _,PetObject in pairs(Pets:GetChildren()) do
  31. PetData[#PetData + 1] = {
  32. Name = PetObject.Name,
  33. TotalXP = PetObject.TotalXP.Value,
  34. Equipped = PetObject.Equipped.Value,
  35. PetID = PetObject.PetID.Value,
  36. Multiplier1 = PetObject.Multiplier1.Value,
  37. Multiplier2 = PetObject.Multiplier2.Value,
  38. Type = PetObject.Type.Value
  39. }
  40. end
  41. for _,DataValue in pairs(Data:GetChildren()) do
  42. PlayerData[#PlayerData + 1] = {
  43. Name = DataValue.Name,
  44. ClassName = DataValue.ClassName,
  45. Value = DataValue.Value
  46. }
  47. end
  48.  
  49. Datastore:SetAsync(plr.UserId, {["PetData"] = PetData, ["PlayerData"] = PlayerData})
  50. end)
  51.  
  52. Players.PlayerAdded:Connect(function(plr)
  53. local Pets = Instance.new("Folder")
  54. local Data = Instance.new("Folder")
  55.  
  56. local SavedData = Datastore:GetAsync(plr.UserId)
  57.  
  58. Pets.Name = "Pets"
  59. Data.Name = "Data"
  60.  
  61. if SavedData ~= nil then
  62. local PetData = SavedData.PetData
  63. local PlayerData = SavedData.PlayerData
  64. for i,v in pairs(PetData) do
  65. local PetObject = RS.Pets.PetFolderTemplate:Clone()
  66. local Settings = RS.Pets.Models:FindFirstChild(v.Name).Settings
  67. local TypeNumber = RS.Pets.CraftingTiers:FindFirstChild(v.Type).Value
  68. local Level = getLevel(v.TotalXP)
  69. PetObject.Name = v.Name
  70. PetObject.Equipped.Value = v.Equipped
  71. PetObject.TotalXP.Value = v.TotalXP
  72. PetObject.Multiplier1.Value = Settings.Multiplier1.Value *(1*(plr.Upgrades.Multiplier1Upgrade.Value) +1) * (RS.Pets.Settings.CraftMultiplier.Value ^ TypeNumber) + (Settings.LevelIncrement.Value * Level)
  73. PetObject.Multiplier2.Value = Settings.Multiplier2.Value *(1*(plr.Upgrades.Multiplier2Upgrade.Value) +1) * (RS.Pets.Settings.CraftMultiplier.Value ^ TypeNumber) + (Settings.LevelIncrement.Value * Level)
  74. PetObject.PetID.Value = v.PetID
  75. PetObject.Type.Value = v.Type
  76. PetObject.Parent = Pets
  77. end
  78. for i,v in pairs(script.Data:GetChildren()) do
  79. local DataValue = v:Clone()
  80. local DataTable = nil
  81. DataValue.Parent = Data
  82. for i,v in pairs(PlayerData) do
  83. if v.Name == DataValue.Name then
  84. DataTable = v
  85. end
  86. end
  87. if DataTable ~= nil then
  88. if DataValue.Name == "MaxStorage" or v.Name == "MaxEquipped" then
  89. DataValue.Value = RS.Pets.Settings:FindFirstChild("Default".. DataValue.Name).Value
  90. else
  91. DataValue.Value = DataTable.Value
  92. end
  93. else
  94. if DataValue.Name == "MaxStorage" or v.Name == "MaxEquipped" then
  95. DataValue.Value = RS.Pets.Settings:FindFirstChild("Default".. DataValue.Name).Value
  96. end
  97. end
  98. end
  99. else
  100. for i,v in pairs(script.Data:GetChildren()) do
  101. local DataValue = v:Clone()
  102. DataValue.Parent = Data
  103. if DataValue.Name == "MaxStorage" or v.Name == "MaxEquipped" then
  104. DataValue.Value = RS.Pets.Settings:FindFirstChild("Default".. DataValue.Name).Value
  105. end
  106. end
  107. end
  108.  
  109. Pets.Parent = plr
  110. Data.Parent = plr
  111. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement