Help with Egg System Triple Hatch

so ive been trying to make three times hatch for a while now and i kind of got it working but the eggs themselves are not working right i modified the one x hatch and tripled it to get it to work
it adds the 3 random pets to my inventory but the effect does not work properly
Video:
robloxapp-20240314-1011046.wmv (2.3 MB)

Script

local Player = game:GetService("Players").LocalPlayer
local WorkSpace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local EggRemoteEvents = ReplicatedStorage:WaitForChild("EggRemoteEvents")
local Camera = WorkSpace.CurrentCamera
local Eggs = require(ReplicatedStorage:WaitForChild("Eggs"):WaitForChild("ModuleScript"))

local openBillboardUI = script.Parent.Parent:FindFirstChildOfClass("BillboardGui")
local container = openBillboardUI:WaitForChild("Container")

--[[local PetDisplay = script.Parent.Parent:WaitForChild("PetDisplay")
local PetDisplay2 = script.Parent.Parent:WaitForChild("PetDisplay2")
local PetDisplay3 = script.Parent.Parent:WaitForChild("PetDisplay3")]]

local GamePassService = game:GetService("GamePassService")

-- Function to check if the player has a specific game pass
local function hasGamePass(player, gamePassId)
	return GamePassService:PlayerHasPass(player, gamePassId)
end
local hatchSpeed = 1.2
local hatchOneConnection = nil


-- Modify hatch speed based on game pass ownership
local function adjustHatchSpeed()
	if hasGamePass(Player, 741822901) then
		hatchSpeed = 4 -- or any other value you want for double hatch speed
	else
		hatchSpeed = 2 -- default hatch speed
	end
end

local function hatchOneEgg(eggName, petName)
	adjustHatchSpeed()
	container.Visible = false
	local Module = Eggs[eggName]
	local Pets = Module["Pets"]
	
	local PetDisplay = script.Parent.Parent:WaitForChild("PetDisplay"):Clone()
	PetDisplay.Parent = script.Parent
	
	PetDisplay:WaitForChild("UIScale").Scale = 0
	Player.Character.PrimaryPart.Anchored = true
	
	local EggMesh = ReplicatedStorage:WaitForChild("Eggs"):WaitForChild(eggName):Clone()
	EggMesh.Parent = Camera
	
	EggMesh.Transparency = 1
	Camera.CameraType = Enum.CameraType.Scriptable
	TweenService:Create(Camera, TweenInfo.new(0.35/hatchSpeed, Enum.EasingStyle.Back), {FieldOfView = 85}):Play()
	TweenService:Create(EggMesh, TweenInfo.new(0.5/hatchSpeed), {Transparency = 0}):Play()
	
	hatchOneConnection = RunService.RenderStepped:Connect(function()
		local cf = CFrame.new(0,0,-EggMesh.Size.Z * 1.5) * CFrame.Angles(0,0,math.sin(time() * 18)/(2.3/hatchSpeed))
		EggMesh.CFrame = (Camera.CFrame * cf)
	end)
	
	task.wait(4/hatchSpeed)
	hatchOneConnection:Disconnect()
	EggMesh:Destroy()

	local petMesh = ReplicatedStorage:WaitForChild("Pets"):WaitForChild(petName):Clone()
	petMesh.Parent = Camera
	PetDisplay.Visible = true
	PetDisplay:WaitForChild("PetNameDisplay").Text = petName
	if petMesh:GetAttribute("Secret") == true then
		PetDisplay:WaitForChild("PetRarityDisplay").TextColor3 = petMesh:GetAttribute("Rarity_Color")
		PetDisplay:WaitForChild("PetRarityDisplay").Text = "Secret"
	else
		PetDisplay:WaitForChild("PetRarityDisplay").TextColor3 = petMesh:GetAttribute("Rarity_Color")
		PetDisplay:WaitForChild("PetRarityDisplay").Text = tostring(petMesh:GetAttribute("Rarity_Name")).." ("..tostring(Pets[petName][2]).."%)"
	end
	local scalePetDisplay = TweenService:Create(PetDisplay:WaitForChild("UIScale"), TweenInfo.new(0.6/hatchSpeed, Enum.EasingStyle.Back), {
		Scale = 1
	})
	scalePetDisplay:Play()
	
	hatchOneConnection = RunService.RenderStepped:Connect(function()
		local cf = CFrame.new(0,0,-petMesh.PrimaryPart.Size.Z * petMesh:GetAttribute("SizeHatch")) * CFrame.Angles((-0.05), ((1.5*hatchSpeed)*tick() * 2 % (math.pi * 2)), 0)
		petMesh.PrimaryPart.CFrame = (Camera.CFrame * cf)
	end)
	task.wait(4/hatchSpeed)
	hatchOneConnection:Disconnect()
	local cf = CFrame.new(0,0,-petMesh.PrimaryPart.Size.Z * petMesh:GetAttribute("SizeHatch")) * CFrame.Angles(0, 160.25, 0)
	TweenService:Create(petMesh.PrimaryPart, TweenInfo.new(0.75/hatchSpeed, Enum.EasingStyle.Back), {
		CFrame = (Camera.CFrame * cf)
	}):Play()
	
	
	task.wait(1/hatchSpeed)
	local hidePet = TweenService:Create(petMesh.PrimaryPart, TweenInfo.new(1.5/hatchSpeed), {
		CFrame = petMesh.PrimaryPart.CFrame - Vector3.new(0,10,0)
	})
	local hidePetDisplay = TweenService:Create(PetDisplay, TweenInfo.new(0.75/hatchSpeed, Enum.EasingStyle.Back), {
		Position = UDim2.new(0.5,0, 2,0)
	})
	hidePet:Play()
	hidePetDisplay:Play()
	hidePet.Completed:Connect(function()
		petMesh:Destroy()
		PetDisplay:Destroy()
		Camera.CameraType = Enum.CameraType.Follow
		TweenService:Create(Camera, TweenInfo.new(0.35/hatchSpeed, Enum.EasingStyle.Back), {FieldOfView = 70}):Play()
		Player.Character.PrimaryPart.Anchored = false
		container.Visible = true
	end)
end

local function hatchThreeEgg(eggName, petName)
	adjustHatchSpeed()
	container.Visible = false
	local Module = Eggs[eggName]
	local Pets = Module["Pets"]

	local EggMesh1 = ReplicatedStorage:WaitForChild("Eggs"):WaitForChild(eggName):Clone()
	local EggMesh2 = ReplicatedStorage:WaitForChild("Eggs"):WaitForChild(eggName):Clone()
	local EggMesh3 = ReplicatedStorage:WaitForChild("Eggs"):WaitForChild(eggName):Clone()

	local PetDisplay1 = script.Parent.Parent:WaitForChild("PetDisplay"):Clone()
	local PetDisplay2 = script.Parent.Parent:WaitForChild("PetDisplay"):Clone()
	local PetDisplay3 = script.Parent.Parent:WaitForChild("PetDisplay"):Clone()

	PetDisplay1.Parent = script.Parent
	PetDisplay2.Parent = script.Parent
	PetDisplay3.Parent = script.Parent

	local eggMeshes = {EggMesh1, EggMesh2, EggMesh3}
	local petDisplays = {PetDisplay1, PetDisplay2, PetDisplay3}

	for i = 1, 3 do
		eggMeshes[i].Parent = Camera
		eggMeshes[i].Transparency = 1

		local cf = CFrame.new((i - 2) * 5, 0, 0) -- Adjust the position of each egg
		eggMeshes[i].CFrame = cf

		TweenService:Create(eggMeshes[i], TweenInfo.new(0.5 / hatchSpeed), {Transparency = 0}):Play()
	end

	Camera.CameraType = Enum.CameraType.Scriptable
	TweenService:Create(Camera, TweenInfo.new(0.35 / hatchSpeed, Enum.EasingStyle.Back), {FieldOfView = 85}):Play()

	task.wait(4 / hatchSpeed)

	for i = 1, 3 do
		eggMeshes[i]:Destroy()
	end

	local petMeshes = {}

	for i = 1, 3 do
		petMeshes[i] = ReplicatedStorage:WaitForChild("Pets"):WaitForChild(petName):Clone()
		petMeshes[i].Parent = Camera
		petDisplays[i].Visible = true
		petDisplays[i]:WaitForChild("PetNameDisplay").Text = petName

		if petMeshes[i]:GetAttribute("Secret") == true then
			petDisplays[i]:WaitForChild("PetRarityDisplay").TextColor3 = petMeshes[i]:GetAttribute("Rarity_Color")
			petDisplays[i]:WaitForChild("PetRarityDisplay").Text = "Secret"
		else
			petDisplays[i]:WaitForChild("PetRarityDisplay").TextColor3 = petMeshes[i]:GetAttribute("Rarity_Color")
			petDisplays[i]:WaitForChild("PetRarityDisplay").Text = tostring(petMeshes[i]:GetAttribute("Rarity_Name")).." ("..tostring(Pets[petName][2]).."%)"
		end

		local scalePetDisplay = TweenService:Create(petDisplays[i]:WaitForChild("UIScale"), TweenInfo.new(0.6 / hatchSpeed, Enum.EasingStyle.Back), {
			Scale = 1
		})
		scalePetDisplay:Play()

		local cf = CFrame.new((i - 2) * 5, 0, 0) -- Adjust the position of each pet
		TweenService:Create(petMeshes[i].PrimaryPart, TweenInfo.new(0.75 / hatchSpeed, Enum.EasingStyle.Back), {
			CFrame = (Camera.CFrame * cf)
		}):Play()
	end

	task.wait(1 / hatchSpeed)

	for i = 1, 3 do
		local hidePet = TweenService:Create(petMeshes[i].PrimaryPart, TweenInfo.new(1.5 / hatchSpeed), {
			CFrame = petMeshes[i].PrimaryPart.CFrame - Vector3.new(0, 10, 0)
		})
		local hidePetDisplay = TweenService:Create(petDisplays[i], TweenInfo.new(0.75 / hatchSpeed, Enum.EasingStyle.Back), {
			Position = UDim2.new(0.5, 0, 2, 0)
		})
		hidePet:Play()
		hidePetDisplay:Play()
		hidePet.Completed:Connect(function()
			petMeshes[i]:Destroy()
			petDisplays[i]:Destroy()
			Camera.CameraType = Enum.CameraType.Follow
			TweenService:Create(Camera, TweenInfo.new(0.35 / hatchSpeed, Enum.EasingStyle.Back), {FieldOfView = 70}):Play()
			Player.Character.PrimaryPart.Anchored = false
			container.Visible = true
		end)
	end
end




EggRemoteEvents:WaitForChild("hatchOne").OnClientEvent:Connect(function(eggName, petName)
	hatchOneEgg(eggName, petName)
end)

EggRemoteEvents:WaitForChild("hatchTriple").OnClientEvent:Connect(function(eggName, petName)
	hatchThreeEgg(eggName, petName)
end)
1 Like