4bcuy

hd 1

May 1st, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.93 KB | None | 0 0
  1. local TS = game:GetService("TweenService")
  2. local MS = game:GetService("MarketplaceService")
  3. local RS = game.ReplicatedStorage
  4. local Library = RS.Pets
  5. local Eggs = require(Library:WaitForChild("Eggs"))
  6. local RemoteEvents = RS.RemoteEvents
  7. local EggModels = workspace.Eggs
  8.  
  9. local PlayerDebounce = {}
  10.  
  11. function ChoosePet(Egg)
  12. local Data = Eggs[Egg]
  13. local Pets = Data["Pets"]
  14. local TotalWeight = 0
  15. for i,v in pairs(Pets) do
  16. TotalWeight = TotalWeight + v.Rarity
  17. end
  18. local Chance = math.random(1,TotalWeight)
  19. local Counter = 0
  20. for i,v in pairs(Pets) do
  21. Counter = Counter+v.Rarity
  22. if Counter >= Chance then
  23. return v.Name
  24. end
  25. end
  26. end
  27.  
  28. function totalPets(Player)
  29. local Pets = 0
  30. for i,v in pairs(Player.Pets:GetChildren()) do
  31. Pets = Pets + 1
  32. end
  33. return Pets
  34. end
  35.  
  36. function RandomID(Player)
  37. local Rand = math.random(2,1000000)
  38. for i,v in pairs(Player.Pets:GetChildren()) do
  39. if v.PetID.Value == Rand then
  40. return RandomID()
  41. end
  42. end
  43. return Rand
  44. end
  45.  
  46. function singleEgg(Player, Egg)
  47. local Data = Eggs[Egg]
  48. local Cost = Data["Cost"]
  49. local Currency = Data["Currency"]
  50. local Pets = Data["Pets"]
  51. local PetChosen = ChoosePet(Egg)
  52. local Settings = RS.Pets.Models:FindFirstChild(PetChosen).Settings
  53. if Currency ~= "R$" then
  54. Player.leaderstats:FindFirstChild(Currency).Value = Player.leaderstats:FindFirstChild(Currency).Value - Cost
  55. Player.leaderstats:FindFirstChild("Eggs").Value = Player.leaderstats:FindFirstChild("Eggs").Value + 1
  56. end
  57. for i,v in pairs(PlayerDebounce) do
  58. if v[1] == Player.Name then
  59. v[2] = true
  60. end
  61. end
  62. spawn(function()
  63. wait(3.2)
  64. for i,v in pairs(PlayerDebounce) do
  65. if v[1] == Player.Name then
  66. v[2] = false
  67. end
  68. end
  69. end)
  70. for i,v in pairs(Pets) do
  71. if v.Name == PetChosen then
  72. local Clone = RS.Pets.PetFolderTemplate:Clone()
  73. Clone.PetID.Value = RandomID(Player)
  74. Clone.Multiplier1.Value = Settings.Multiplier1.Value
  75. Clone.Multiplier2.Value = Settings.Multiplier2.Value
  76. Clone.Type.Value = v.Type
  77. Clone.Parent = Player.Pets
  78. Clone.Name = PetChosen
  79. end
  80. end
  81. return PetChosen
  82. end
  83.  
  84. function tripleEgg(Player, Egg)
  85. local Data = Eggs[Egg]
  86. local Cost = Data["Cost"]
  87. local Currency = Data["Currency"]
  88. local Pets = Data["Pets"]
  89. local PetsChosen = {}
  90. Player.leaderstats:FindFirstChild(Currency).Value = Player.leaderstats:FindFirstChild(Currency).Value - Cost * 3
  91. Player.leaderstats:FindFirstChild("Eggs").Value = Player.leaderstats:FindFirstChild("Eggs").Value + 3
  92. for i,v in pairs(PlayerDebounce) do
  93. if v[1] == Player.Name then
  94. v[2] = true
  95. end
  96. end
  97. spawn(function()
  98. wait(3.2)
  99. for i,v in pairs(PlayerDebounce) do
  100. if v[1] == Player.Name then
  101. v[2] = false
  102. end
  103. end
  104. end)
  105. for i = 1,3 do
  106. local PetChosen = ChoosePet(Egg)
  107. local Settings = RS.Pets.Models:FindFirstChild(PetChosen).Settings
  108. for i,v in pairs(Pets) do
  109. if v.Name == PetChosen then
  110. local Clone = RS.Pets.PetFolderTemplate:Clone()
  111. Clone.PetID.Value = RandomID(Player)
  112. Clone.Multiplier1.Value = Settings.Multiplier1.Value
  113. Clone.Multiplier2.Value = Settings.Multiplier2.Value
  114. Clone.Type.Value = v.Type
  115. Clone.Parent = Player.Pets
  116. Clone.Name = PetChosen
  117. PetsChosen[#PetsChosen + 1] = PetChosen
  118. end
  119. end
  120. end
  121. return PetsChosen
  122. end
  123.  
  124. function UnboxEgg(Player, Egg, Type)
  125. if Eggs[Egg] ~= nil then
  126. local Data = Eggs[Egg]
  127. local Cost = Data["Cost"]
  128. local Currency = Data["Currency"]
  129. local Pets = Data["Pets"]
  130. local Model = EggModels:FindFirstChild(Egg)
  131. local Debounce = false
  132. for i,v in pairs(PlayerDebounce) do
  133. if v[1] == Player.Name then
  134. Debounce = v[2]
  135. end
  136. end
  137. if (Player.Character.HumanoidRootPart.Position - Model.UIanchor.Position).Magnitude <= 10 then
  138. if not Debounce then
  139. if Currency ~= "R$" then
  140. if Type == "Single" then
  141. if Player.leaderstats:FindFirstChild(Currency).Value >= Cost then
  142. if totalPets(Player) < Player.Data.MaxStorage.Value then
  143. local PetChosen = singleEgg(Player, Egg)
  144. return PetChosen
  145. else
  146. return "Error", "Not Enough Inventory Room"
  147. end
  148. else
  149. return "Error", "Insufficient Currency"
  150. end
  151. elseif Type == "Triple" then
  152. if Player.leaderstats:FindFirstChild(Currency).Value >= Cost * 3 then
  153. if totalPets(Player) < Player.Data.MaxStorage.Value - 2 then
  154. if Player.Data.TripleEggOwned.Value == true then
  155. local PetsChosen = tripleEgg(Player, Egg)
  156. return PetsChosen
  157. else
  158. return "Error", "Player Doesn't Own Gamepass"
  159. end
  160. else
  161. return "Error", "Not Enough Inventory Room"
  162. end
  163. else
  164. return "Error", "Insufficient Currency"
  165. end
  166. elseif Type == "Auto" then
  167. if Player.Data.AutoEggOwned.Value == true then
  168. if Player.Data.TripleEggOwned.Value == true then
  169. if Player.leaderstats:FindFirstChild(Currency).Value >= Cost * 3 then
  170. if totalPets(Player) < Player.Data.MaxStorage.Value - 2 then
  171. if Player.Data.TripleEggOwned.Value == true then
  172. local PetsChosen = tripleEgg(Player, Egg)
  173. return PetsChosen
  174. else
  175. return "Error", "Player Doesn't Own Gamepass"
  176. end
  177. else
  178. return "Error", "Not Enough Inventory Room"
  179. end
  180. else
  181. return "Error", "Insufficient Currency"
  182. end
  183. else
  184. if Player.leaderstats:FindFirstChild(Currency).Value >= Cost then
  185. if totalPets(Player) < Player.Data.MaxStorage.Value then
  186. local PetChosen = singleEgg(Player, Egg)
  187. return PetChosen
  188. else
  189. return "Error", "Not Enough Inventory Room"
  190. end
  191. else
  192. return "Error", "Insufficient Currency"
  193. end
  194. end
  195. else
  196. return "Error", "Player Doesn't Own Gamepass"
  197. end
  198. end
  199. else
  200. if totalPets(Player) < Player.Data.MaxStorage.Value then
  201. return "Error", "Robux Purchase"
  202. else
  203. return "Error", "Not Enough Inventory Room"
  204. end
  205. end
  206. end
  207. else
  208. return "Error", "Too far away"
  209. end
  210. end
  211. end
  212.  
  213. game.Players.PlayerAdded:Connect(function(plr)
  214. PlayerDebounce[#PlayerDebounce + 1] = {plr.Name, false}
  215. end)
  216.  
  217. game.Players.PlayerRemoving:Connect(function(plr)
  218. for i,v in pairs(PlayerDebounce) do
  219. if v[1] == plr.Name then
  220. v = nil
  221. end
  222. end
  223. end)
  224.  
  225. for i,v in pairs(Eggs) do
  226. local ProductID = v["ProductID"]
  227. if ProductID ~= nil then
  228. MS.ProcessReceipt = function(ReceiptInfo)
  229. local Player = game:GetService("Players"):GetPlayerByUserId(ReceiptInfo.PlayerId)
  230. if ReceiptInfo.ProductId == ProductID then
  231. spawn(function()
  232. local Result = singleEgg(Player, i)
  233. RS.RemoteEvents.EggOpened:InvokeClient(Player, Eggs[i], Result)
  234. end)
  235. return Enum.ProductPurchaseDecision.PurchaseGranted
  236. end
  237. end
  238. end
  239. end
  240.  
  241. RS.RemoteEvents.EggOpened.OnServerInvoke = UnboxEgg
Add Comment
Please, Sign In to add comment