Cakey3101

Eggs System Client

May 13th, 2025
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.82 KB | Source Code | 0 0
  1. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  2. local RunService = game:GetService("RunService")
  3. local Players = game:GetService("Players")
  4. local TweenService = game:GetService("TweenService")
  5. local UserInputService = game:GetService("UserInputService")
  6. local MarketPlaceService = game:GetService("MarketplaceService")
  7.  
  8. local Player = Players.LocalPlayer
  9. local PlayerGui = Player.PlayerGui
  10.  
  11. local Module3D = require(ReplicatedStorage.Libs.Module3D)
  12.  
  13. local Gui = PlayerGui:WaitForChild("Eggs")
  14. local EggBillboardsFolder = Gui.EggBillboards
  15.  
  16. local ChaosFolder = ReplicatedStorage:WaitForChild("Chaos")
  17. local Eggs = workspace:WaitForChild("Eggs")
  18.  
  19. local MaxDisplayDistance = 15
  20. local CanHatch = false
  21. local IsHatching = false
  22. local HatchOneConnection = nil
  23. local CannotOpenBillboard = false
  24. local Cooldown = false
  25.  
  26. local function AnimateBillboard(Billboard: BillboardGui, Open: boolean)
  27.     if Open == true then
  28.         local Tween = TweenService:Create(Billboard, TweenInfo.new(0.1), {Size = UDim2.fromScale(5, 7)})
  29.         Tween:Play()
  30.     else
  31.         local Tween = TweenService:Create(Billboard, TweenInfo.new(0.1), {Size = UDim2.fromScale(0, 0)})
  32.         Tween:Play()
  33.         Tween.Completed:Connect(function()
  34.             task.wait(0.2)
  35.             Billboard.Enabled = false
  36.         end)
  37.     end
  38.  
  39.     task.wait(0.5)
  40. end
  41.  
  42. local function ToggleAllScreenGuis(Bool: boolean)
  43.     if Bool == false then
  44.         for i, v in PlayerGui:GetChildren() do
  45.             if v.Name ~= "Eggs" then
  46.                 v.Enabled = false
  47.             end
  48.         end
  49.     else
  50.         for i, v in PlayerGui:GetChildren() do
  51.             if v.Name == "Main" or v.Name == "Eggs" then
  52.                 v.Enabled = true
  53.             end
  54.         end
  55.     end
  56. end
  57.  
  58. local function DisableAllBillboards()
  59.     CannotOpenBillboard = true
  60.     for i, v in pairs(EggBillboardsFolder:GetChildren()) do
  61.         if v:IsA("BillboardGui") then
  62.             AnimateBillboard(v, false)
  63.         end
  64.     end
  65. end
  66.  
  67. local function EnableAllBillboards()
  68.     CannotOpenBillboard = false
  69.     for i, v in pairs(EggBillboardsFolder:GetChildren()) do
  70.         if v:IsA("BillboardGui") then
  71.             AnimateBillboard(v, true)
  72.         end
  73.     end
  74. end
  75.  
  76. for i, v in pairs(Eggs:GetChildren()) do
  77.     local EggChaos = ChaosFolder:FindFirstChild(v.Name)
  78.  
  79.     if EggChaos ~= nil then
  80.         local BillboardTemplate = script.Template:Clone()
  81.         local Container = BillboardTemplate:WaitForChild("Container")
  82.         local MainFrame = Container:WaitForChild("MainFrame")
  83.         local Template = MainFrame:WaitForChild("Template")
  84.         local Display = Template:WaitForChild("Display")
  85.  
  86.         BillboardTemplate.Parent = EggBillboardsFolder
  87.         BillboardTemplate.Name = v.Name
  88.         BillboardTemplate.Adornee = v:WaitForChild("EggMesh")
  89.         BillboardTemplate.Enabled = true
  90.  
  91.         local Chaos = {}
  92.  
  93.         for x, Chao in pairs(EggChaos:GetChildren()) do
  94.             table.insert(Chaos, Chao.Rarity.Value)
  95.         end
  96.  
  97.         table.sort(Chaos)
  98.  
  99.         for i = 1, math.floor(#Chaos / 2) do
  100.             local j = #Chaos - i + 1
  101.             Chaos[i], Chaos[j] = Chaos[j], Chaos[i]
  102.         end
  103.  
  104.         for x, c in pairs(Chaos) do
  105.             print(c)
  106.         end
  107.  
  108.         for _, Rarity in pairs(Chaos) do
  109.             for _, Chao in pairs(EggChaos:GetChildren()) do
  110.                 if Chao.Rarity.Value == Rarity then
  111.                     local Rarity = Chao.Rarity
  112.  
  113.                     local ClonedTemplate = Template:Clone()
  114.  
  115.                     ClonedTemplate.Name = Chao.Name
  116.                     ClonedTemplate.Rarity.Text = `{tostring(Chao.Rarity.Value)}%`
  117.                     ClonedTemplate.Visible = true
  118.                     ClonedTemplate.Parent = MainFrame
  119.  
  120.                     local ChaoModel = Module3D:Attach3D(ClonedTemplate.Display, Chao:Clone())
  121.                     ChaoModel:SetDepthMultiplier(1.2)
  122.                     ChaoModel.Camera.FieldOfView = 5
  123.                     ChaoModel.Visible = true
  124.  
  125.                     RunService.PreRender:Connect(function()
  126.                         ChaoModel:SetCFrame(CFrame.Angles(0, tick() * 2 % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
  127.                     end)
  128.  
  129.                     break
  130.                 else
  131.                     continue
  132.                 end
  133.             end
  134.  
  135.             RunService.PreRender:Connect(function()
  136.                 if Player:DistanceFromCharacter(v.EggMesh.PrimaryPart.Position) < MaxDisplayDistance then
  137.                     if CannotOpenBillboard == false then
  138.                         BillboardTemplate.Enabled = true
  139.                         AnimateBillboard(BillboardTemplate, true)
  140.                     end
  141.                 else
  142.                     if CannotOpenBillboard == false then
  143.                         AnimateBillboard(BillboardTemplate, false)
  144.                     end
  145.                 end
  146.             end)
  147.         end
  148.     end
  149. end
  150.  
  151. local function HatchOne(ChaoName, Egg)
  152.     spawn(function()
  153.         DisableAllBillboards()
  154.     end)
  155.     ToggleAllScreenGuis(false)
  156.    
  157.     workspace:WaitForChild("Camera").CameraType = Enum.CameraType.Scriptable
  158.     TweenService:Create(workspace:WaitForChild("Camera"), TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {CFrame = Egg:FindFirstChild("CameraPart").CFrame}):Play()
  159.    
  160.     Gui.PetDisplay.PetName.Text = ChaoName
  161.  
  162.     local Chao = ChaosFolder:FindFirstChild(Egg.Name):FindFirstChild(ChaoName):Clone()
  163.     IsHatching = true
  164.  
  165.     local EggMesh = Egg:FindFirstChild("EggMesh"):Clone()
  166.  
  167.     for i, v in pairs(EggMesh:GetChildren()) do
  168.         if v:IsA("BasePart") then
  169.             v.Anchored = true
  170.             v.CanCollide = false
  171.         end
  172.     end
  173.  
  174.     HatchOneConnection = RunService.PreRender:Connect(function()
  175.         local cframe = CFrame.new(0, 0, -EggMesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(0, 0, math.sin(time() * 18) / 2.3)
  176.         EggMesh.PrimaryPart.CFrame = workspace.Camera.CFrame * cframe
  177.     end)
  178.  
  179.     EggMesh.Parent = workspace.Camera
  180.  
  181.     task.wait(3)
  182.  
  183.     for i, v in pairs(EggMesh:GetChildren()) do
  184.         if v:IsA("BasePart") then
  185.             TweenService:Create(v, TweenInfo.new(0.5), {Transparency = 1}):Play()
  186.         end
  187.     end
  188.  
  189.     task.wait(0.5)
  190.     HatchOneConnection:Disconnect()
  191.     EggMesh:Destroy()
  192.  
  193.     Gui.PetDisplay.Visible = true
  194.  
  195.     local ChaoModel = Module3D:Attach3D(Gui.PetDisplay, Chao)
  196.     ChaoModel:SetDepthMultiplier(1.2)
  197.     ChaoModel.Camera.FieldOfView = 5
  198.     ChaoModel.Visible = true
  199.  
  200.     RunService.PreRender:Connect(function()
  201.         ChaoModel:SetCFrame(CFrame.Angles(0, tick() * 2 % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
  202.     end)
  203.  
  204.     task.wait(3)
  205.  
  206.     TweenService:Create(Gui.PetDisplay:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
  207.     task.wait(0.5)
  208.  
  209.     for i, v in pairs(Gui.PetDisplay:GetDescendants()) do
  210.         if v:IsA("ViewportFrame") then
  211.             v:Destroy()
  212.         end
  213.     end
  214.  
  215.     Gui.PetDisplay.Visible = false
  216.  
  217.     IsHatching = false
  218.  
  219.     spawn(function()
  220.         EnableAllBillboards()
  221.     end)
  222.     ToggleAllScreenGuis(true)
  223.     _G.NewTemplate(ChaoName)
  224.     workspace:WaitForChild("Camera").CameraType = Enum.CameraType.Follow
  225. end
  226.  
  227. local function TripleHatch(ChaoName, ChaoName2, ChaoName3, Egg)
  228.     spawn(function()
  229.         DisableAllBillboards()
  230.     end)
  231.     ToggleAllScreenGuis(false)
  232.    
  233.     workspace:WaitForChild("Camera").CameraType = Enum.CameraType.Scriptable
  234.     TweenService:Create(workspace:WaitForChild("Camera"), TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {CFrame = Egg:FindFirstChild("CameraPart").CFrame}):Play()
  235.  
  236.     local Chao = ChaosFolder[Egg.Name]:FindFirstChild(ChaoName):Clone()
  237.     local Chao2 = ChaosFolder[Egg.Name]:FindFirstChild(ChaoName2):Clone()
  238.     local Chao3 = ChaosFolder[Egg.Name]:FindFirstChild(ChaoName3):Clone()
  239.  
  240.     Gui.PetDisplay.PetName.Text = ChaoName
  241.     Gui.PetDisplay2.PetName.Text = ChaoName2
  242.     Gui.PetDisplay3.PetName.Text = ChaoName3
  243.  
  244.     IsHatching = true
  245.  
  246.     local EggMesh = Egg:FindFirstChild("EggMesh"):Clone()
  247.     local EggMesh2 = Egg:FindFirstChild("EggMesh"):Clone()
  248.     local EggMesh3 = Egg:FindFirstChild("EggMesh"):Clone()
  249.  
  250.     for i, v in pairs(EggMesh:GetChildren()) do
  251.         if v:IsA("BasePart") then
  252.             v.Anchored = true
  253.             v.CanCollide = false
  254.         end
  255.     end
  256.  
  257.     for i, v in pairs(EggMesh2:GetChildren()) do
  258.         if v:IsA("BasePart") then
  259.             v.Anchored = true
  260.             v.CanCollide = false
  261.         end
  262.     end
  263.  
  264.     for i, v in pairs(EggMesh3:GetChildren()) do
  265.         if v:IsA("BasePart") then
  266.             v.Anchored = true
  267.             v.CanCollide = false
  268.         end
  269.     end
  270.  
  271.     HatchOneConnection = RunService.PreRender:Connect(function()
  272.         local cframe = CFrame.new(0, 0, -EggMesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(0, 0, math.sin(time() * 18) / 2.3)
  273.         local cframe2 = CFrame.new(6, 0, -EggMesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(0, 0, math.sin(time() * 18) / 2.3)
  274.         local cframe3 = CFrame.new(-6, 0, -EggMesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(0, 0, math.sin(time() * 18) / 2.3)
  275.         EggMesh.PrimaryPart.CFrame = workspace.Camera.CFrame * cframe
  276.         EggMesh2.PrimaryPart.CFrame = workspace.Camera.CFrame * cframe2
  277.         EggMesh3.PrimaryPart.CFrame = workspace.Camera.CFrame * cframe3
  278.     end)
  279.  
  280.     EggMesh.Parent = workspace.Camera
  281.     EggMesh2.Parent = workspace.Camera
  282.     EggMesh3.Parent = workspace.Camera
  283.  
  284.     task.wait(3)
  285.  
  286.     for i, v in pairs(EggMesh:GetChildren()) do
  287.         if v:IsA("BasePart") then
  288.             TweenService:Create(v, TweenInfo.new(0.5), {Transparency = 1}):Play()
  289.         end
  290.     end
  291.  
  292.     for i, v in pairs(EggMesh2:GetChildren()) do
  293.         if v:IsA("BasePart") then
  294.             TweenService:Create(v, TweenInfo.new(0.5), {Transparency = 1}):Play()
  295.         end
  296.     end
  297.  
  298.     for i, v in pairs(EggMesh3:GetChildren()) do
  299.         if v:IsA("BasePart") then
  300.             TweenService:Create(v, TweenInfo.new(0.5), {Transparency = 1}):Play()
  301.         end
  302.     end
  303.  
  304.     task.wait(0.5)
  305.     HatchOneConnection:Disconnect()
  306.     EggMesh:Destroy()
  307.     EggMesh2:Destroy()
  308.     EggMesh3:Destroy()
  309.  
  310.     Gui.PetDisplay.Visible = true
  311.     Gui.PetDisplay2.Visible = true
  312.     Gui.PetDisplay3.Visible = true
  313.  
  314.     local ChaoModel = Module3D:Attach3D(Gui.PetDisplay, Chao)
  315.     ChaoModel:SetDepthMultiplier(1.2)
  316.     ChaoModel.Camera.FieldOfView = 5
  317.     ChaoModel.Visible = true
  318.  
  319.     local ChaoModel2 = Module3D:Attach3D(Gui.PetDisplay2, Chao2)
  320.     ChaoModel2:SetDepthMultiplier(1.2)
  321.     ChaoModel2.Camera.FieldOfView = 5
  322.     ChaoModel2.Visible = true
  323.  
  324.     local ChaoModel3 = Module3D:Attach3D(Gui.PetDisplay3, Chao3)
  325.     ChaoModel3:SetDepthMultiplier(1.2)
  326.     ChaoModel3.Camera.FieldOfView = 5
  327.     ChaoModel3.Visible = true
  328.  
  329.     RunService.PreRender:Connect(function()
  330.         ChaoModel:SetCFrame(CFrame.Angles(0, tick() * 2 % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
  331.         ChaoModel2:SetCFrame(CFrame.Angles(0, tick() * 2 % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
  332.         ChaoModel3:SetCFrame(CFrame.Angles(0, tick() * 2 % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
  333.     end)
  334.  
  335.     task.wait(3)
  336.  
  337.     TweenService:Create(Gui.PetDisplay:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
  338.     TweenService:Create(Gui.PetDisplay2:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
  339.     TweenService:Create(Gui.PetDisplay3:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
  340.  
  341.     task.wait(0.5)
  342.  
  343.     for i, v in pairs(Gui.PetDisplay:GetDescendants()) do
  344.         if v:IsA("ViewportFrame") then
  345.             v:Destroy()
  346.         end
  347.     end
  348.  
  349.     for i, v in pairs(Gui.PetDisplay2:GetDescendants()) do
  350.         if v:IsA("ViewportFrame") then
  351.             v:Destroy()
  352.         end
  353.     end
  354.  
  355.     for i, v in pairs(Gui.PetDisplay3:GetDescendants()) do
  356.         if v:IsA("ViewportFrame") then
  357.             v:Destroy()
  358.         end
  359.     end
  360.  
  361.     Gui.PetDisplay.Visible = false
  362.     Gui.PetDisplay2.Visible = false
  363.     Gui.PetDisplay3.Visible = false
  364.  
  365.     IsHatching = false
  366.  
  367.     spawn(function()
  368.         EnableAllBillboards()
  369.     end)
  370.     ToggleAllScreenGuis(true)
  371.     _G.NewTemplate(ChaoName)
  372.     _G.NewTemplate(ChaoName2)
  373.     _G.NewTemplate(ChaoName3)
  374.  
  375.     workspace:WaitForChild("Camera").CameraType = Enum.CameraType.Follow
  376. end
  377.  
  378. UserInputService.InputBegan:Connect(function(Input: InputObject, GameProcessedEvent: boolean)
  379.     if GameProcessedEvent then return end
  380.  
  381.     if Input.KeyCode == Enum.KeyCode.E then
  382.         if Player.Character ~= nil and IsHatching == false then
  383.             local NearestEgg
  384.             local PlayerPosition = Player.Character:WaitForChild("HumanoidRootPart").Position
  385.  
  386.             for i, v in pairs(Eggs:GetChildren()) do
  387.                 if NearestEgg == nil then
  388.                     NearestEgg = v
  389.                 else
  390.                     if (PlayerPosition - v:WaitForChild("EggMesh").Position).Magnitude < (NearestEgg:WaitForChild("EggMesh").Position - PlayerPosition).Magnitude then
  391.                         NearestEgg = v
  392.                     end
  393.                 end
  394.             end
  395.  
  396.             if Player:DistanceFromCharacter(NearestEgg.EggMesh.PrimaryPart.CFrame.Position) < MaxDisplayDistance then
  397.                 CanHatch = true
  398.             else
  399.                 CanHatch = false
  400.             end
  401.  
  402.             if CanHatch == true then
  403.                 local Result = ReplicatedStorage:WaitForChild("Remotes").Chaos.HatchServer:InvokeServer(NearestEgg)
  404.  
  405.                 if Result ~= "Cannot Hatch" then
  406.                     if not Cooldown then
  407.                         Cooldown = true
  408.                         HatchOne(Result, NearestEgg)
  409.                         task.wait(0.1)
  410.                         Cooldown = false
  411.                     end
  412.                 else
  413.                     print("Cannot Hatch")
  414.                 end
  415.             end
  416.         end
  417.     end
  418.  
  419.     if Input.KeyCode == Enum.KeyCode.R then
  420.         if Player.Character ~= nil and IsHatching == false then
  421.             local NearestEgg
  422.             local PlayerPosition = Player.Character:WaitForChild("HumanoidRootPart").Position
  423.  
  424.             for i, v in pairs(Eggs:GetChildren()) do
  425.                 if NearestEgg == nil then
  426.                     NearestEgg = v
  427.                 else
  428.                     if (PlayerPosition - v:WaitForChild("EggMesh").Position).Magnitude < (NearestEgg:WaitForChild("EggMesh").Position - PlayerPosition).Magnitude then
  429.                         NearestEgg = v
  430.                     end
  431.                 end
  432.             end
  433.  
  434.             if Player:DistanceFromCharacter(NearestEgg.EggMesh.PrimaryPart.CFrame.Position) < MaxDisplayDistance then
  435.                 CanHatch = true
  436.             else
  437.                 CanHatch = false
  438.             end
  439.  
  440.             if CanHatch == true then
  441.                 local Result1, Result2, Result3 = ReplicatedStorage:WaitForChild("Remotes").Chaos.Hatch3Chaos:InvokeServer(NearestEgg)
  442.  
  443.                 if Result1 ~= "The Player Does Not Own The Gamepass" and Result2 ~= nil and Result3 ~= nil then
  444.                     if not Cooldown then
  445.                         Cooldown = true
  446.                         TripleHatch(Result1, Result2, Result3, NearestEgg)
  447.                         task.wait(0.1)
  448.                         Cooldown = false
  449.                     end
  450.                 elseif Result1 == "The Player Does Not Own The Gamepass" then
  451.                     MarketPlaceService:PromptGamePassPurchase(Player, 1209923362)
  452.                 end
  453.             end
  454.         end
  455.     end
  456. end)
  457.  
  458. for i, v in pairs(EggBillboardsFolder:GetChildren()) do
  459.     local EButton = v.Container.Buttons.E
  460.     local RButton = v.Container.Buttons.R
  461.  
  462.     EButton.MouseButton1Click:Connect(function()
  463.         local NearestEgg
  464.         local PlayerPosition = Player.Character:WaitForChild("HumanoidRootPart").Position
  465.  
  466.         for i, v in pairs(Eggs:GetChildren()) do
  467.             if NearestEgg == nil then
  468.                 NearestEgg = v
  469.             else
  470.                 if (PlayerPosition - v:WaitForChild("EggMesh").Position).Magnitude < (NearestEgg:WaitForChild("EggMesh").Position - PlayerPosition).Magnitude then
  471.                     NearestEgg = v
  472.                 end
  473.             end
  474.         end
  475.  
  476.         if Player:DistanceFromCharacter(NearestEgg.EggMesh.PrimaryPart.CFrame.Position) < MaxDisplayDistance then
  477.             CanHatch = true
  478.         else
  479.             CanHatch = false
  480.         end
  481.  
  482.         if CanHatch == true then
  483.             local Result = ReplicatedStorage:WaitForChild("Remotes").Chaos.HatchServer:InvokeServer(NearestEgg)
  484.  
  485.             if Result ~= "Cannot Hatch" then
  486.                 if not Cooldown then
  487.                     Cooldown = true
  488.                     HatchOne(Result, NearestEgg)
  489.                     task.wait(0.1)
  490.                     Cooldown = false
  491.                 end
  492.             else
  493.                 print("Cannot Hatch")
  494.             end
  495.         end
  496.     end)
  497.    
  498.     RButton.MouseButton1Click:Connect(function()
  499.         if Player.Character ~= nil and IsHatching == false then
  500.             local NearestEgg
  501.             local PlayerPosition = Player.Character:WaitForChild("HumanoidRootPart").Position
  502.  
  503.             for i, v in pairs(Eggs:GetChildren()) do
  504.                 if NearestEgg == nil then
  505.                     NearestEgg = v
  506.                 else
  507.                     if (PlayerPosition - v:WaitForChild("EggMesh").Position).Magnitude < (NearestEgg:WaitForChild("EggMesh").Position - PlayerPosition).Magnitude then
  508.                         NearestEgg = v
  509.                     end
  510.                 end
  511.             end
  512.  
  513.             if Player:DistanceFromCharacter(NearestEgg.EggMesh.PrimaryPart.CFrame.Position) < MaxDisplayDistance then
  514.                 CanHatch = true
  515.             else
  516.                 CanHatch = false
  517.             end
  518.  
  519.             if CanHatch == true then
  520.                 local Result1, Result2, Result3 = ReplicatedStorage:WaitForChild("Remotes").Chaos.Hatch3Chaos:InvokeServer(NearestEgg)
  521.  
  522.                 if Result1 ~= "The Player Does Not Own The Gamepass" and Result2 ~= nil and Result3 ~= nil then
  523.                     if not Cooldown then
  524.                         Cooldown = true
  525.                         TripleHatch(Result1, Result2, Result3, NearestEgg)
  526.                         task.wait(0.1)
  527.                         Cooldown = false
  528.                     end
  529.                 elseif Result1 == "The Player Does Not Own The Gamepass" then
  530.                     MarketPlaceService:PromptGamePassPurchase(Player, 1209923362)
  531.                 end
  532.             end
  533.         end
  534.     end)
  535. end
Tags: robloxstudio
Advertisement
Add Comment
Please, Sign In to add comment