Advertisement
DragonSploitsYT

Untitled

Jul 20th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.03 KB | None | 0 0
  1. local RS = game.ReplicatedStorage
  2. local MS = game:GetService("MarketplaceService")
  3.  
  4. function GetFolderFromPetID(Player, PetID)
  5. for i,v in pairs(Player.Pets:GetChildren()) do
  6. if v.PetID.Value == PetID then
  7. return v
  8. end
  9. end
  10. return nil
  11. end
  12.  
  13. function GetPointOnCircle(CircleRadius, Degrees)
  14. return Vector3.new(math.cos(math.rad(Degrees)) * CircleRadius, 1, math.sin(math.rad(Degrees))* CircleRadius)
  15. end
  16.  
  17. function GetAllOfType(Player, PetName, Type)
  18. local Pets = {}
  19. for i,v in pairs(Player.Pets:GetChildren()) do
  20. if v.Name == PetName then
  21. if v:WaitForChild("Type").Value == Type then
  22. Pets[#Pets + 1] = v.PetID.Value
  23. end
  24. end
  25. end
  26. if #Pets >= RS.Pets.Settings.PetsRequiredToCraft.Value then
  27. return Pets
  28. else
  29. return nil
  30. end
  31. end
  32.  
  33. function GetNextType(TypeName)
  34. local CurrentValue
  35. for i,v in pairs(RS.Pets.CraftingTiers:GetChildren()) do
  36. if v.Name == TypeName then
  37. CurrentValue = v.Value
  38. end
  39. end
  40. for i,v in pairs(RS.Pets.CraftingTiers:GetChildren()) do
  41. if v.Value == CurrentValue + 1 then
  42. return v.Name, CurrentValue + 1
  43. end
  44. end
  45. end
  46.  
  47. function RandomID(Player)
  48. local Rand = math.random(2,1000000)
  49. for i,v in pairs(Player.Pets:GetChildren()) do
  50. if v.PetID.Value == Rand then
  51. return RandomID()
  52. end
  53. end
  54. return Rand
  55. end
  56.  
  57. function loadEquipped(Player)
  58. local CurrentlyEquipped = {}
  59. for _,Pet in pairs(Player:WaitForChild("Pets"):GetChildren()) do
  60. if Pet.Equipped.Value == true then
  61. CurrentlyEquipped[#CurrentlyEquipped + 1] = Pet.PetID.Value
  62. else
  63. local ExistentModel = nil
  64. for _,Part in pairs(workspace.PlayerPets:FindFirstChild(Player.Name):GetChildren()) do
  65. if Part:FindFirstChild("PetID") then
  66. if Part.PetID.Value == Pet.PetID.Value then
  67. ExistentModel = Part
  68. end
  69. end
  70. end
  71. if ExistentModel ~= nil then
  72. ExistentModel:Destroy()
  73. end
  74. end
  75. end
  76. local Increment = 360/#CurrentlyEquipped
  77. for i,v in pairs(CurrentlyEquipped) do
  78. local ExistentModel = nil
  79. local Folder = GetFolderFromPetID(Player, v)
  80. for _,Part in pairs(workspace.PlayerPets:FindFirstChild(Player.Name):GetChildren()) do
  81. if Part:FindFirstChild("PetID") then
  82. if Part.PetID.Value == v then
  83. ExistentModel = Part
  84. end
  85. end
  86. end
  87. if ExistentModel ~= nil then
  88. ExistentModel.Pos.Value = GetPointOnCircle(RS.Pets.Settings.PetCircleRadius.Value, Increment * i)
  89. else
  90. local PetModel = RS.Pets.Models:FindFirstChild(Folder.Name):FindFirstChild(Folder.Type.Value):Clone()
  91. PetModel.Pos.Value = GetPointOnCircle(RS.Pets.Settings.PetCircleRadius.Value, Increment * i)
  92. PetModel.PetID.Value = v
  93. PetModel.Parent = workspace.PlayerPets:FindFirstChild(Player.Name)
  94. PetModel.PrimaryPart:SetNetworkOwner(Player)
  95. end
  96. end
  97. end
  98.  
  99. function ActionRequest(Player, Action, Parameters)
  100. if Action == "Equip" then
  101. local Folder = GetFolderFromPetID(Player, Parameters.PetID)
  102. if Folder ~= nil then
  103. if Folder.Equipped.Value == false then
  104. local TotalEquipped = 0
  105. for i,v in pairs(Player.Pets:GetChildren()) do
  106. if v.Equipped.Value == true then
  107. TotalEquipped = TotalEquipped + 1
  108. end
  109. end
  110. if TotalEquipped < Player.Data.MaxEquip.Value then
  111. Folder.Equipped.Value = true
  112. loadEquipped(Player)
  113. return "Success"
  114. else
  115. return "Error", "Too Many Pets Equipped"
  116. end
  117. else
  118. return "Error", "Pet Already Equipped"
  119. end
  120. else
  121. return "Error", "Invalid Pet"
  122. end
  123. elseif Action == "Unequip" then
  124. local Folder = GetFolderFromPetID(Player, Parameters.PetID)
  125. if Folder ~= nil then
  126. if Folder.Equipped.Value == true then
  127. Folder.Equipped.Value = false
  128. loadEquipped(Player)
  129. return "Success"
  130. else
  131. return "Error", "Pet Already Unequipped"
  132. end
  133. else
  134. return "Error", "Invalid Pet"
  135. end
  136. elseif Action == "Delete" then
  137. local Folder = GetFolderFromPetID(Player, Parameters.PetID)
  138. if Folder ~= nil then
  139. Folder.Equipped.Value = false
  140. loadEquipped(Player)
  141. Folder:Destroy()
  142. return "Success"
  143. else
  144. return "Error", "Invalid Pet"
  145. end
  146. elseif Action == "Craft" then
  147. local MainFolder = GetFolderFromPetID(Player, Parameters.PetID)
  148. local MainType = MainFolder.Type.Value
  149. local MainName = MainFolder.Name
  150. if MainFolder ~= nil then
  151. local Pets = GetAllOfType(Player, MainFolder.Name, MainFolder.Type.Value)
  152. if Pets ~= nil then
  153. for i = 1,RS.Pets.Settings.PetsRequiredToCraft.Value do
  154. local Folder = GetFolderFromPetID(Player, Pets[i])
  155. Folder.Equipped.Value = false
  156. loadEquipped(Player)
  157. Folder:Destroy()
  158. end
  159. local Clone = RS.Pets.PetFolderTemplate:Clone()
  160. local Type, TypeNumber = GetNextType(MainType)
  161. local Settings = RS.Pets.Models:FindFirstChild(MainName).Settings
  162. Clone.PetID.Value = RandomID(Player)
  163. Clone.Multiplier1.Value = Settings.Multiplier1.Value * (RS.Pets.Settings.CraftMultiplier.Value ^ TypeNumber)
  164. Clone.Multiplier2.Value = Settings.Multiplier2.Value * (RS.Pets.Settings.CraftMultiplier.Value ^ TypeNumber)
  165. Clone.Type.Value = Type
  166. Clone.Parent = Player.Pets
  167. Clone.Name = MainName
  168. return Clone.PetID.Value
  169. else
  170. return "Error", "Not Enough Pets"
  171. end
  172. else
  173. return "Error", "Invalid Pet"
  174. end
  175. elseif Action == "Mass Delete" then
  176. for i,v in pairs(Parameters.Pets) do
  177. local Folder = GetFolderFromPetID(Player, v)
  178. if Folder ~= nil then
  179. Folder.Equipped.Value = false
  180. loadEquipped(Player)
  181. Folder:Destroy()
  182. end
  183. end
  184. end
  185. end
  186.  
  187. RS.RemoteEvents.PetActionRequest.OnServerInvoke = ActionRequest
  188. RS.RemoteEvents.plrWalk.OnServerEvent:Connect(function(Player, State)
  189. Player.Data:FindFirstChild("isWalking").Value = State
  190. end)
  191.  
  192. game.Players.PlayerAdded:Connect(function(Player)
  193. Player.CharacterAppearanceLoaded:Connect(function()
  194. local Folder = Instance.new("Folder", workspace.PlayerPets)
  195. Folder.Name = Player.Name
  196. loadEquipped(Player)
  197. end)
  198. end)
  199.  
  200. game.Players.PlayerRemoving:Connect(function(Player)
  201. local Folder = workspace.PlayerPets:FindFirstChild(Player.Name)
  202. if Folder then
  203. Folder:Destroy()
  204. end
  205. end)
  206.  
  207. -- Gamepasses
  208.  
  209. for i,v in pairs(RS.GamepassIDs:GetChildren()) do
  210. MS.PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
  211. if purchased and v.Value == ido then
  212. if v.Name == "TripleOpen" then
  213. plr.Data.TripleEggOwned.Value = true
  214. elseif v.Name == "AutoOpen" then
  215. plr.Data.AutoEggOwned.Value = true
  216. elseif v.Name == "ExtraStorage" then
  217. plr.Data.MaxStorage.Value = plr.Data.MaxStorage.Value +30
  218. elseif v.Name == "+50ExtraStorage" then
  219. plr.Data.MaxStorage.Value = plr.Data.MaxStorage.Value +50
  220. elseif v.Name == "+150ExtraStorage" then
  221. plr.Data.MaxStorage.Value = plr.Data.MaxStorage.Value +150
  222. elseif v.Name == "ExtraEquipped" then
  223. plr.Data.MaxEquip.Value = 6
  224. elseif v.Name == "+3ExtraEquipped" then
  225. plr.Data.MaxEquip.Value = plr.Data.MaxEquip.Value +3
  226. elseif v.Name == "+5ExtraEquipped" then
  227. plr.Data.MaxEquip.Value = plr.Data.MaxEquip.Value +5
  228. end
  229. end
  230. end)
  231. game.Players.PlayerAdded:Connect(function(plr)
  232. local Data = plr:WaitForChild("Data", math.huge)
  233. if MS:UserOwnsGamePassAsync(plr.UserId, v.Value) then
  234. if v.Name == "TripleOpen" then
  235. plr.Data.TripleEggOwned.Value = true
  236. end
  237. if v.Name == "AutoOpen" then
  238. plr.Data.AutoEggOwned.Value = true
  239. end
  240. if v.Name == "+150ExtraStorage" then
  241. plr.Data.MaxStorage.Value = plr.Data.MaxStorage.Value +150
  242. end
  243. if v.Name == "+50ExtraStorage" then
  244. plr.Data.MaxStorage.Value = plr.Data.MaxStorage.Value +50
  245. end
  246. if v.Name == "ExtraStorage" then
  247. plr.Data.MaxStorage.Value = plr.Data.MaxStorage.Value +30
  248. end
  249. if v.Name == "ExtraEquipped" then
  250. plr.Data.MaxEquip.Value = 6
  251. end
  252. if v.Name == "+3ExtraEquipped" then
  253. plr.Data.MaxEquip.Value = plr.Data.MaxEquip.Value +3
  254. end
  255. if v.Name == "+5ExtraEquipped" then
  256. plr.Data.MaxEquip.Value = plr.Data.MaxEquip.Value +5
  257. end
  258.  
  259. end
  260. end)
  261. end
  262. -- Setup
  263.  
  264. for _,Folder in pairs(RS.Pets.Models:GetChildren()) do
  265. for _,Model in pairs(Folder:GetChildren()) do
  266. if Model.Name ~= "Settings" then
  267. local PetID = script.PetSetup.PetID:Clone()
  268. local Pos = script.PetSetup.Pos:Clone()
  269. local BG = script.PetSetup.BodyGyro:Clone()
  270. local BP = script.PetSetup.BodyPosition:Clone()
  271. local FollowScript = script.PetSetup.Follow:Clone()
  272. local LevelingScript = script.PetSetup.Leveling:Clone()
  273. PetID.Parent = Model
  274. Pos.Parent = Model
  275. BG.Parent = Model.PrimaryPart
  276. BP.Parent = Model.PrimaryPart
  277. FollowScript.Parent = Model
  278. LevelingScript.Parent = Model
  279. end
  280. end
  281. end
  282.  
  283. -- Global Pet Float
  284.  
  285. local maxFloat = .88
  286. local floatInc = 0.065
  287. local sw = false
  288. local fl = 0
  289.  
  290. spawn(function()
  291. while true do
  292. wait()
  293. if not sw then
  294. fl = fl + floatInc
  295. if fl >= maxFloat then
  296. sw = true
  297. end
  298. else
  299. fl = fl - floatInc
  300. if fl <=-maxFloat then
  301. sw = false
  302. end
  303. end
  304. script.Parent.globalPetFloat.Value = fl
  305. end
  306. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement