Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Initializing various services provided by Roblox to interact with the game. ReplicatedStorage, RunService, TweenService, UserInputService, and MarketplaceService are essential for different aspects of game.
- ]]--
- local replicatedStorage = game:GetService("ReplicatedStorage")
- local runService = game:GetService("RunService")
- local tweenService = game:GetService("TweenService")
- local uis = game:GetService("UserInputService")
- local mps = game:GetService("MarketplaceService")
- --Gamepass IDs
- local tripleHatchID = 24274065
- local autoHatchId = 32338581
- --Getting local player and their camera
- local player = game.Players.LocalPlayer
- local camera = workspace.Camera
- -- Accessing important assets in game, such as pets and eggs. we also requiring a module for 3D UIs (Viewport).
- local Pets = replicatedStorage:WaitForChild("Pets")
- local Eggs = workspace:WaitForChild("Eggs")
- local Module3D = require(replicatedStorage:WaitForChild("Module3D"))
- local stopAutoHatching = script.Parent.Parent:WaitForChild("StopAutoHatching")
- --These variables controls various states of game, including distances, hatching status, and cooldowns.
- local MaxDisplayDistance = 15
- local canHatch = false
- local isHatching = false
- local hatchOneConnection = nil
- local cantOpenBillboard = false
- local cooldown = false
- local IsAutoHatching = false
- wait(.5)
- -- Define a function to animate the size of a BillboardGui based on a boolean parameter.
- local function animateBillboard(billboard, openOrClose)
- if openOrClose == true then
- -- If openOrClose is true, tween the size to expand the Billboard.
- tweenService:Create(billboard,TweenInfo.new(.1),{Size = UDim2.new(5,0,7,0)}):Play()
- else
- -- If openOrClose is false, tween the size to collapse the Billboard and disable it after a short delay.
- tweenService:Create(billboard,TweenInfo.new(.1),{Size = UDim2.new(0,0,0,0)}):Play()
- wait(.2)
- billboard.Enabled = false
- end
- wait(.5)
- end
- -- Define a function to toggle the visibility of screen GUIs.
- local function ToggleScreenGuis(bool)
- for i, v in pairs(script.Parent.Parent.Parent:GetChildren()) do
- if v.Name ~= "EggSystem" then
- v.Enabled = bool
- end
- end
- end
- -- Define a function to disable all Billboards by animating them to close.
- local function disableAllBillboards()
- cantOpenBillboard = true
- for i, v in pairs(script.Parent.Parent.EggBillboards:GetChildren()) do
- if v:IsA("BillboardGui") then
- animateBillboard(v, false)
- end
- end
- end
- -- Define a function to enable all Billboards by animating them to open.
- local function EnableAllBillboards()
- cantOpenBillboard = false
- for i, v in pairs(script.Parent.Parent.EggBillboards:GetChildren()) do
- if v:IsA("BillboardGui") then
- animateBillboard(v, true)
- end
- end
- end
- -- Iterate through each child of the 'Eggs' object.
- for i, v in pairs(Eggs:GetChildren()) do
- -- Check if the current egg has corresponding pets in the 'Pets' object.
- local eggPets = Pets:FindFirstChild(v.Name)
- if eggPets ~= nil then
- -- Create a BillboardGui template for each egg and configure its contents based on pet rarities.
- local billboardTemp = script.Template:Clone()
- local container = billboardTemp:WaitForChild("Container")
- local MainFrame = container:WaitForChild("MainFrame")
- local template = MainFrame:WaitForChild("Template")
- local display = template:WaitForChild("Display")
- billboardTemp.Parent = script.Parent.Parent.EggBillboards
- billboardTemp.Name = v.Name
- billboardTemp.Adornee = v.EggMesh
- billboardTemp.Enabled = true
- local pets = {}
- for x, pet in pairs(eggPets:GetChildren()) do
- table.insert(pets,pet.Rarity.Value)
- end
- table.sort(pets)
- for i = 1, math.floor(#pets/2) do
- local j = #pets - i + 1
- pets[i], pets[j] = pets[j], pets[i]
- end
- for _, rarity in pairs(pets) do
- for _, pet in pairs(eggPets:GetChildren()) do
- if pet.Rarity.Value == rarity then
- local rarity = pet.Rarity.Value
- -- Attach 3D models to the BillboardGui to display pets.
- local clonedTemp = template:Clone()
- clonedTemp.Name = pet.Name
- clonedTemp.Rarity.Text = tostring(pet.Rarity.Value).."%"
- clonedTemp.Visible = true
- clonedTemp.Parent = MainFrame
- local petModel = Module3D:Attach3D(clonedTemp.Display,pet:Clone())
- petModel:SetDepthMultiplier(1.2)
- petModel.Camera.FieldOfView = 5
- petModel.Visible = true
- runService.RenderStepped:Connect(function()
- petModel:SetCFrame(CFrame.Angles(0,tick() * 2 % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
- end)
- break
- else
- continue
- end
- end
- end
- -- Set up a RenderStepped connection to dynamically show/hide Billboards based on player distance.
- runService.RenderStepped:Connect(function()
- if player:DistanceFromCharacter(v.EggMesh.PrimaryPart.Position) < MaxDisplayDistance then
- if cantOpenBillboard == false then
- billboardTemp.Enabled = true
- animateBillboard(billboardTemp, true)
- end
- else
- if cantOpenBillboard == false then
- animateBillboard(billboardTemp, false)
- end
- end
- end)
- end
- end
- -- Define a function to handle hatching a single pet from an egg.
- local function hatchOne(petName, egg)
- -- Spawn a function to disable all Billboards and toggle screen GUIs during the hatching process.
- spawn(function() disableAllBillboards() end)
- ToggleScreenGuis(false)
- script.Parent.Parent.PetDisplay.PetNameDisplay.Text = petName
- local pet = Pets[egg.Name]:FindFirstChild(petName):Clone()
- isHatching = true
- local eggMesh = egg:FindFirstChild("EggMesh"):Clone()
- for i, v in pairs(eggMesh:GetChildren()) do
- if v:IsA("BasePart") then
- v.Anchored = true
- v.CanCollide = false
- end
- end
- -- Set up the 3D display for the hatched pet and animate the hatching process.
- hatchOneConnection = runService.RenderStepped:Connect(function()
- local cf = CFrame.new(0,0,-eggMesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(0,0,math.sin(time() * 18)/2.3)
- eggMesh:SetPrimaryPartCFrame(camera.CFrame * cf)
- end)
- eggMesh.Parent = camera
- print("Hatching")
- wait(3)
- for i, v in pairs(eggMesh:GetChildren()) do
- if v:IsA("BasePart") then
- tweenService:Create(v,TweenInfo.new(.5),{Transparency = 1}):Play()
- end
- end
- wait(.5)
- hatchOneConnection:Disconnect()
- eggMesh:Destroy()
- script.Parent.Parent.PetDisplay.Visible = true
- local petModel = Module3D:Attach3D(script.Parent.Parent.PetDisplay,pet)
- petModel:SetDepthMultiplier(1.2)
- petModel.Camera.FieldOfView = 5
- petModel.Visible = true
- -- Enable Billboards and toggle screen GUIs back to their original state.
- runService.RenderStepped:Connect(function()
- petModel:SetCFrame(CFrame.Angles(0,tick() * 2 % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
- end)
- wait(3)
- tweenService:Create(script.Parent.Parent.PetDisplay:FindFirstChildOfClass("ViewportFrame"),TweenInfo.new(.5),{ImageTransparency = 1}):Play()
- wait(.5)
- for i, v in pairs(script.Parent.Parent.PetDisplay:GetDescendants()) do
- if v:IsA("ViewportFrame") then
- v:Destroy()
- end
- end
- script.Parent.Parent.PetDisplay.Visible = false
- isHatching = false
- -- Call a function to handle the creation of a new template for the hatched pet.
- spawn(function() EnableAllBillboards() end)
- ToggleScreenGuis(true)
- _G.newTemplate(petName)
- camera.CameraType = Enum.CameraType.Follow
- end
- -- Define a function to handle hatching three pets from eggs.
- local function tripleHatch(petName,petName2,petName3,egg)
- -- Similar structure to the hatchOne function, but for hatching three pets simultaneously.
- spawn(function() disableAllBillboards() end)
- ToggleScreenGuis(false)
- local pet = Pets[egg.Name]:FindFirstChild(petName):Clone()
- local pet2 = Pets[egg.Name]:FindFirstChild(petName2):Clone()
- local pet3 = Pets[egg.Name]:FindFirstChild(petName3):Clone()
- script.Parent.Parent.PetDisplay.PetNameDisplay.Text = petName
- script.Parent.Parent.PetDisplay2.PetNameDisplay.Text = petName2
- script.Parent.Parent.PetDisplay3.PetNameDisplay.Text = petName3
- isHatching = true
- local eggMesh = egg:FindFirstChild("EggMesh"):Clone()
- local eggMesh2 = egg:FindFirstChild("EggMesh"):Clone()
- local eggMesh3 = egg:FindFirstChild("EggMesh"):Clone()
- for i, v in pairs(eggMesh:GetChildren()) do
- if v:IsA("BasePart") then
- v.Anchored = true
- v.CanCollide = false
- end
- end
- for i, v in pairs(eggMesh2:GetChildren()) do
- if v:IsA("BasePart") then
- v.Anchored = true
- v.CanCollide = false
- end
- end
- for i, v in pairs(eggMesh3:GetChildren()) do
- if v:IsA("BasePart") then
- v.Anchored = true
- v.CanCollide = false
- end
- end
- - Set up 3D displays for each pet and animate the hatching process for all three.
- hatchOneConnection = runService.RenderStepped:Connect(function()
- local cf = CFrame.new(0,0,-eggMesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(0,0,math.sin(time() * 18)/2.3)
- local cf2 = CFrame.new(6,0,-eggMesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(0,0,math.sin(time() * 18)/2.3)
- local cf3 = CFrame.new(-6,0,-eggMesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(0,0,math.sin(time() * 18)/2.3)
- eggMesh:SetPrimaryPartCFrame(camera.CFrame * cf)
- eggMesh2:SetPrimaryPartCFrame(camera.CFrame * cf2)
- eggMesh3:SetPrimaryPartCFrame(camera.CFrame * cf3)
- end)
- eggMesh.Parent = camera
- eggMesh2.Parent = camera
- eggMesh3.Parent = camera
- print("Hatching")
- wait(3)
- for i, v in pairs(eggMesh:GetChildren()) do
- if v:IsA("BasePart") then
- tweenService:Create(v,TweenInfo.new(.5),{Transparency = 1}):Play()
- end
- end
- for i, v in pairs(eggMesh2:GetChildren()) do
- if v:IsA("BasePart") then
- tweenService:Create(v,TweenInfo.new(.5),{Transparency = 1}):Play()
- end
- end
- for i, v in pairs(eggMesh3:GetChildren()) do
- if v:IsA("BasePart") then
- tweenService:Create(v,TweenInfo.new(.5),{Transparency = 1}):Play()
- end
- end
- wait(.5)
- hatchOneConnection:Disconnect()
- eggMesh:Destroy()
- eggMesh2:Destroy()
- eggMesh3:Destroy()
- script.Parent.Parent.PetDisplay.Visible = true
- script.Parent.Parent.PetDisplay2.Visible = true
- script.Parent.Parent.PetDisplay3.Visible = true
- local petModel = Module3D:Attach3D(script.Parent.Parent.PetDisplay,pet)
- petModel:SetDepthMultiplier(1.2)
- petModel.Camera.FieldOfView = 5
- petModel.Visible = true
- local petModel2 = Module3D:Attach3D(script.Parent.Parent.PetDisplay2,pet2)
- petModel2:SetDepthMultiplier(1.2)
- petModel2.Camera.FieldOfView = 5
- petModel2.Visible = true
- local petModel3 = Module3D:Attach3D(script.Parent.Parent.PetDisplay3,pet3)
- petModel3:SetDepthMultiplier(1.2)
- petModel3.Camera.FieldOfView = 5
- petModel3.Visible = true
- runService.RenderStepped:Connect(function()
- petModel:SetCFrame(CFrame.Angles(0,tick() * 2 % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
- petModel2:SetCFrame(CFrame.Angles(0,tick() * 2 % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
- petModel3:SetCFrame(CFrame.Angles(0,tick() * 2 % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
- end)
- wait(3)
- tweenService:Create(script.Parent.Parent.PetDisplay:FindFirstChildOfClass("ViewportFrame"),TweenInfo.new(.5),{ImageTransparency = 1}):Play()
- tweenService:Create(script.Parent.Parent.PetDisplay2:FindFirstChildOfClass("ViewportFrame"),TweenInfo.new(.5),{ImageTransparency = 1}):Play()
- tweenService:Create(script.Parent.Parent.PetDisplay3:FindFirstChildOfClass("ViewportFrame"),TweenInfo.new(.5),{ImageTransparency = 1}):Play()
- wait(.5)
- for i, v in pairs(script.Parent.Parent.PetDisplay:GetDescendants()) do
- if v:IsA("ViewportFrame") then
- v:Destroy()
- end
- end
- for i, v in pairs(script.Parent.Parent.PetDisplay2:GetDescendants()) do
- if v:IsA("ViewportFrame") then
- v:Destroy()
- end
- end
- for i, v in pairs(script.Parent.Parent.PetDisplay3:GetDescendants()) do
- if v:IsA("ViewportFrame") then
- v:Destroy()
- end
- end
- script.Parent.Parent.PetDisplay.Visible = false
- script.Parent.Parent.PetDisplay2.Visible = false
- script.Parent.Parent.PetDisplay3.Visible = false
- isHatching = false
- spawn(function() EnableAllBillboards() end)
- ToggleScreenGuis(true)
- _G.newTemplate(petName)
- _G.newTemplate(petName2)
- _G.newTemplate(petName3)
- camera.CameraType = Enum.CameraType.Follow
- end
- -- Set up an input listener for specific key presses (E, R, T) to trigger different hatching actions.
- uis.InputBegan:Connect(function(input)
- -- Handle input for hatching a single pet (E key).
- if input.KeyCode == Enum.KeyCode.E then
- if player.Character ~= nil and isHatching == false then
- local nearestEgg
- local plrPos = player.Character.HumanoidRootPart.Position
- for i, v in pairs(Eggs:GetChildren()) do
- if nearestEgg == nil then
- nearestEgg = v
- else
- if (plrPos - v.PrimaryPart.Position).Magnitude < (nearestEgg.PrimaryPart.Position - plrPos).Magnitude then
- nearestEgg = v
- end
- end
- end
- if player:DistanceFromCharacter(nearestEgg.EggMesh.PrimaryPart.Position) < MaxDisplayDistance then
- canHatch = true
- else
- canHatch = false
- end
- if canHatch == true then
- local result = replicatedStorage:WaitForChild("EggHatchingRemotes"):WaitForChild("HatchServer"):InvokeServer(nearestEgg)
- if result ~= "Cannot Hatch" then
- if not cooldown then
- cooldown = true
- hatchOne(result,nearestEgg)
- wait(.1)
- cooldown = false
- end
- else
- print("Cannot hatch")
- end
- end
- end
- end
- -- Handle input for hatching three pets (R key).
- if input.KeyCode == Enum.KeyCode.R then
- if player.Character ~= nil and isHatching == false then
- local nearestEgg
- local plrPos = player.Character.HumanoidRootPart.Position
- for i, v in pairs(Eggs:GetChildren()) do
- if nearestEgg == nil then
- nearestEgg = v
- else
- if (plrPos - v.PrimaryPart.Position).Magnitude < (nearestEgg.PrimaryPart.Position - plrPos).Magnitude then
- nearestEgg = v
- end
- end
- end
- if player:DistanceFromCharacter(nearestEgg.EggMesh.PrimaryPart.Position) < MaxDisplayDistance then
- canHatch = true
- else
- canHatch = false
- end
- if canHatch == true then
- local result1, result2, result3 = replicatedStorage.EggHatchingRemotes.Hatch3Pets:InvokeServer(nearestEgg)
- if result1 ~= "The player does not own the gamepass" and result2 ~= nil and result3 ~= nil then
- if not cooldown then
- cooldown = true
- tripleHatch(result1, result2,result3,nearestEgg)
- wait(.1)
- cooldown = false
- end
- elseif result1 == "The player does not own the gamepass" then
- mps:PromptGamePassPurchase(player, tripleHatchID)
- end
- end
- end
- end
- -- Handle input for continuously auto-hatching pets until interrupted (T key).
- if input.KeyCode == Enum.KeyCode.T then
- if player.Character ~= nil and isHatching == false then
- local nearestEgg
- local plrPos = player.Character.HumanoidRootPart.Position
- for i, v in pairs(Eggs:GetChildren()) do
- if nearestEgg == nil then
- nearestEgg = v
- else
- if (plrPos - v.PrimaryPart.Position).Magnitude < (nearestEgg.PrimaryPart.Position - plrPos).Magnitude then
- nearestEgg = v
- end
- end
- end
- if player:DistanceFromCharacter(nearestEgg.EggMesh.PrimaryPart.Position) < MaxDisplayDistance then
- canHatch = true
- else
- canHatch = false
- end
- if canHatch == true then
- IsAutoHatching = true
- while IsAutoHatching == true do
- local result = replicatedStorage:WaitForChild("EggHatchingRemotes"):WaitForChild("AutoHatch"):InvokeServer(nearestEgg)
- if result ~= "Cannot Hatch" and result ~= "The player does not own the gamepass" then
- if not cooldown then
- stopAutoHatching.Visible = true
- cooldown = true
- hatchOne(result,nearestEgg)
- wait(.1)
- cooldown = false
- end
- elseif result == "The player does not own the gamepass" then
- mps:PromptGamePassPurchase(player, autoHatchId)
- end
- if IsAutoHatching == false then
- break
- end
- end
- end
- end
- end
- end)
- -- Iterate through each BillboardGui in the EggBillboards and set up mouse button click events for E, R, and T buttons.
- for i, v in pairs(script.Parent.Parent.EggBillboards:GetChildren()) do
- -- Define separate functions for each button click to handle specific hatching actions.
- local Ebtn = v.Container.Buttons.E
- local Rbtn = v.Container.Buttons.R
- local Tbtn = v.Container.Buttons.T
- Ebtn.MouseButton1Click:Connect(function()
- if player.Character ~= nil and isHatching == false then
- local nearestEgg
- local plrPos = player.Character.HumanoidRootPart.Position
- for i, v in pairs(Eggs:GetChildren()) do
- if nearestEgg == nil then
- nearestEgg = v
- else
- if (plrPos - v.PrimaryPart.Position).Magnitude < (nearestEgg.PrimaryPart.Position - plrPos).Magnitude then
- nearestEgg = v
- end
- end
- end
- if player:DistanceFromCharacter(nearestEgg.EggMesh.PrimaryPart.Position) < MaxDisplayDistance then
- canHatch = true
- else
- canHatch = false
- end
- if canHatch == true then
- local result = replicatedStorage:WaitForChild("EggHatchingRemotes"):WaitForChild("HatchServer"):InvokeServer(nearestEgg)
- if result ~= "Cannot Hatch" then
- if not cooldown then
- cooldown = true
- hatchOne(result,nearestEgg)
- wait(.1)
- cooldown = false
- end
- else
- print("Cannot hatch")
- end
- end
- end
- end)
- Rbtn.MouseButton1Click:Connect(function()
- if player.Character ~= nil and isHatching == false then
- local nearestEgg
- local plrPos = player.Character.HumanoidRootPart.Position
- for i, v in pairs(Eggs:GetChildren()) do
- if nearestEgg == nil then
- nearestEgg = v
- else
- if (plrPos - v.PrimaryPart.Position).Magnitude < (nearestEgg.PrimaryPart.Position - plrPos).Magnitude then
- nearestEgg = v
- end
- end
- end
- if player:DistanceFromCharacter(nearestEgg.EggMesh.PrimaryPart.Position) < MaxDisplayDistance then
- canHatch = true
- else
- canHatch = false
- end
- if canHatch == true then
- local result1, result2, result3 = replicatedStorage.EggHatchingRemotes.Hatch3Pets:InvokeServer(nearestEgg)
- if result1 ~= "The player does not own the gamepass" and result2 ~= nil and result3 ~= nil then
- if not cooldown then
- cooldown = true
- tripleHatch(result1, result2,result3,nearestEgg)
- wait(.1)
- cooldown = false
- end
- elseif result1 == "The player does not own the gamepass" then
- mps:PromptGamePassPurchase(player, tripleHatchID)
- end
- end
- end
- end)
- Tbtn.MouseButton1Click:Connect(function()
- if player.Character ~= nil and isHatching == false then
- local nearestEgg
- local plrPos = player.Character.HumanoidRootPart.Position
- for i, v in pairs(Eggs:GetChildren()) do
- if nearestEgg == nil then
- nearestEgg = v
- else
- if (plrPos - v.PrimaryPart.Position).Magnitude < (nearestEgg.PrimaryPart.Position - plrPos).Magnitude then
- nearestEgg = v
- end
- end
- end
- if player:DistanceFromCharacter(nearestEgg.EggMesh.PrimaryPart.Position) < MaxDisplayDistance then
- canHatch = true
- else
- canHatch = false
- end
- if canHatch == true then
- IsAutoHatching = true
- while IsAutoHatching == true do
- local result = replicatedStorage:WaitForChild("EggHatchingRemotes"):WaitForChild("AutoHatch"):InvokeServer(nearestEgg)
- if result ~= "Cannot Hatch" and result ~= "The player does not own the gamepass" then
- if not cooldown then
- stopAutoHatching.Visible = true
- cooldown = true
- hatchOne(result,nearestEgg)
- wait(.1)
- cooldown = false
- end
- elseif result == "The player does not own the gamepass" then
- mps:PromptGamePassPurchase(player, autoHatchId)
- end
- if IsAutoHatching == false then
- break
- end
- end
- end
- end
- end)
- end
- -- Set up a function to stop the auto-hatching process when the stopAutoHatching button is clicked.
- stopAutoHatching.MouseButton1Click:Connect(function()
- IsAutoHatching = false
- stopAutoHatching.Visible = false
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement