Attempt to index nil with name

  1. What do you want to achieve? I want my egg system to work

  2. What is the issue? whenever i hatch only 1 egg, with a button this error shows up

  3. What solutions have you tried so far? Tried look into devhub , yt and searched devforum

local rep = game:GetService("ReplicatedStorage")
local runs = game:GetService("RunService")
local model3D = require(rep:WaitForChild("Module3D"))
local tweeny = game:GetService("TweenService")
local uis = game:GetService("UserInputService")

local plr = game.Players.LocalPlayer
local cam = workspace.Camera
local pets = rep:WaitForChild("Pets")
local eggs = workspace:WaitForChild("Nidus")
local distance  = 40

local canhatch = nil
local ishatch = false
local hatch1connect = nil
local cooldown = false
wait(3)

local function animatebilly(billboard , openorclose)
	if openorclose == true then
		tweeny:Create(billboard, TweenInfo.new(0.1),{Size = UDim2.new(15, 0,20, 0)}):Play()
	else
		tweeny:Create(billboard, TweenInfo.new(0.2),{Size = UDim2.new(0,0,0, 0)}):Play()
		wait(.3)
		billboard.Enabled = false
	end
	wait(1)
end

local function togglegui(bool)
	for i,v in pairs(script.Parent.Parent.Parent:GetChildren()) do
		if v.Name ~= "EggSystem" then
			v.Enabled = bool
		end
	end
end



for i,v in pairs(eggs:GetChildren()) do
	local eggpets = pets:FindFirstChild(v.Name)
	
	if eggpets ~= nil then
		
		
		local billboardtemp = script.Template:Clone()
		local container = billboardtemp:WaitForChild("Cointainer")
		local frame = container:WaitForChild("Main_Frame")
		local template = frame:WaitForChild("Template")
		local billboardegg = script.Parent.Parent.Eggboards
		local port = template:WaitForChild("Port")
		
		billboardtemp.Adornee = v.EggMesh
		billboardtemp.Name = v.Name
		billboardtemp.Enabled = true
		billboardtemp.Parent = billboardegg
		
		local petz = {}

		for x, pet in pairs(eggpets:GetChildren()) do
			table.insert(petz, pet.Rarity.Value)

		end
		table.sort(petz)
		
		for i = 1, math.floor(#petz/2) do
			local j = #petz - i + 1
			petz[i], petz[j] = petz[j], petz[i]
		end
		
		for _,rarity in pairs(petz) do
			for _, pet in pairs(eggpets:GetChildren()) do
				if pet.Rarity.Value == rarity then
					local rarity = pet.Rarity.Value



					local clonedtemp = template:Clone()
					clonedtemp.Name = pet.Name

					clonedtemp.Rarity.Text = tostring(pet.Rarity.Value).."%"
					clonedtemp.Visible = true
					clonedtemp.Parent = frame

					local petmodel = model3D:Attach3D(clonedtemp.Port,pet:Clone())
					petmodel:SetDepthMultiplier(1.2)
					petmodel.Camera.FieldOfView = 5
					petmodel.Visible = true

					runs.RenderStepped:Connect(function()
						petmodel:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(10),0,0))
					end)
					break
				else
					continue
				end
			end
		end
		
	
			
		 runs.RenderStepped:Connect(function()
			if plr:DistanceFromCharacter(v.EggMesh.PrimaryPart.Position) < distance then
					if billboardtemp.Name ~= v.Name then
					canhatch = true
					
					animatebilly(billboardtemp, true)
					billboardtemp.Enabled = true
					else
						canhatch = true
					
					animatebilly(billboardtemp, true)
					billboardtemp.Enabled = true
						
					end
			else
				animatebilly(billboardtemp, false)
				
				canhatch = false
			end
			
		end)
	end
end

local function hatch1(petName,egg)
	print(petName)
	togglegui(false)
	
	local pet = pets[egg.Name]:FindFirstChild(petName):Clone()
	local eggmesh = egg:FindFirstChild("EggMesh"):Clone()
	ishatch = true
	
	script.Parent.Parent.PetDusp.petnaem.Text = tostring(petName)
	print(egg.Name)
	for i,v in pairs(eggmesh:GetChildren()) do
		if v:isA("BasePart") then
			v.Anchored = true
			v.CanCollide = false
		end
	end
	hatch1connect = runs.RenderStepped:Connect(function()
		local cf = CFrame.new(0, 0,-eggmesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(math.sin(time() *4)*2,math.sin(time() *4) *2,math.sin(time() *4) * 2)
		eggmesh:SetPrimaryPartCFrame(cam.CFrame * cf)
	end)
	eggmesh.Parent = cam
	wait(3)
	for i,v in pairs(eggmesh:GetChildren()) do
		if v:isA("BasePart") then
			tweeny:Create(v, TweenInfo.new(0.3),{Transparency = 1}):Play()
		end
	end
	wait(0.3)
	hatch1connect:Disconnect()
	eggmesh:Destroy()
	script.Parent.Parent.PetDusp.Visible = true
	
	local petmodel = model3D:Attach3D(script.Parent.Parent.PetDusp,pet)
	petmodel:SetDepthMultiplier(1.2)
	petmodel.Camera.FieldOfView = 5
	petmodel.Visible = true

	runs.RenderStepped:Connect(function()
		petmodel:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
	end)
	wait(3)
	tweeny:Create(script.Parent.Parent.PetDusp:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
	wait(0.5)
	for i, v in pairs(script.Parent.Parent.PetDusp:GetDescendants()) do
		if v:IsA("ViewportFrame") then
			v:Destroy()
			script.Parent.Parent.PetDusp.Visible = true
		end
	end
	script.Parent.Parent.PetDusp.Visible = false
	
	togglegui(true)
	_G.newTemp(petName)
end

local function triplehatch(petName,petName2,petName3,egg)
	print(egg.Name)
	togglegui(false)
	--where error occurs
	
	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.PetDusp.petnaem.Text = tostring(petName)
	script.Parent.Parent.PetDusp2.petnaem.Text = tostring(petName2)
	script.Parent.Parent.PetDusp3.petnaem.Text = tostring(petName3)
	ishatch = 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
	
	
	hatch1connect = runs.RenderStepped:Connect(function()
		local cf = CFrame.new(0, 0,-eggmesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(math.sin(time() *4)*2,math.sin(time() *4) *2,math.sin(time() *4) * 2)
		eggmesh:SetPrimaryPartCFrame(cam.CFrame * cf)
		
		local cf2 = CFrame.new(6, 0,-eggmesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(math.sin(time() *4)*2,math.sin(time() *4) *2,math.sin(time() *4) * 2)
		eggmesh2:SetPrimaryPartCFrame(cam.CFrame * cf2)
		
		local cf3 = CFrame.new(-6, 0,-eggmesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(math.sin(time() *4)*2,math.sin(time() *4) *2,math.sin(time() *4) * 2)
		eggmesh3:SetPrimaryPartCFrame(cam.CFrame * cf3)
	end)
	eggmesh.Parent = cam
	eggmesh2.Parent = cam
	eggmesh3.Parent = cam
	wait(3)
	ishatch = false
	for i,v in pairs(eggmesh:GetChildren()) do
		if v:isA("BasePart") then
			tweeny:Create(v, TweenInfo.new(0.3),{Transparency = 1}):Play()
		end
	end
	
	for i,v in pairs(eggmesh2:GetChildren()) do
		if v:isA("BasePart") then
			tweeny:Create(v, TweenInfo.new(0.3),{Transparency = 1}):Play()
		end
	end
	
	for i,v in pairs(eggmesh3:GetChildren()) do
		if v:isA("BasePart") then
			tweeny:Create(v, TweenInfo.new(0.3),{Transparency = 1}):Play()
		end
	end
	wait(0.3)
	hatch1connect:Disconnect()
	eggmesh:Destroy()
	eggmesh2:Destroy()
	eggmesh3:Destroy()
	script.Parent.Parent.PetDusp.Visible = true
	script.Parent.Parent.PetDusp2.Visible = true
	script.Parent.Parent.PetDusp3.Visible = true

	local petmodel = model3D:Attach3D(script.Parent.Parent.PetDusp,pet)
	petmodel:SetDepthMultiplier(1.2)
	petmodel.Camera.FieldOfView = 5
	petmodel.Visible = true
	
	local petmodel2 = model3D:Attach3D(script.Parent.Parent.PetDusp2,pet2)
	petmodel2:SetDepthMultiplier(1.2)
	petmodel2.Camera.FieldOfView = 5
	petmodel2.Visible = true
	
	local petmodel3 = model3D:Attach3D(script.Parent.Parent.PetDusp3,pet3)
	petmodel3:SetDepthMultiplier(1.2)
	petmodel3.Camera.FieldOfView = 5
	petmodel3.Visible = true
	

	runs.RenderStepped:Connect(function()
		petmodel:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
		petmodel2:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
		petmodel3:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
	end)
	
	
	wait(3)
	tweeny:Create(script.Parent.Parent.PetDusp:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
	tweeny:Create(script.Parent.Parent.PetDusp2:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
	tweeny:Create(script.Parent.Parent.PetDusp3:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()

	wait(0.5)
	for i, v in pairs(script.Parent.Parent.PetDusp:GetDescendants()) do
		if v:IsA("ViewportFrame") then
			v:Destroy()
			script.Parent.Parent.PetDusp.Visible = true
		end
	end
	
	for i, v in pairs(script.Parent.Parent.PetDusp2:GetDescendants()) do
		if v:IsA("ViewportFrame") then
			v:Destroy()
			script.Parent.Parent.PetDusp2.Visible = true
		end
	end
	
	for i, v in pairs(script.Parent.Parent.PetDusp3:GetDescendants()) do
		if v:IsA("ViewportFrame") then
			v:Destroy()
			script.Parent.Parent.PetDusp3.Visible = true
		end
	end
	script.Parent.Parent.PetDusp.Visible = false
	script.Parent.Parent.PetDusp2.Visible = false
	script.Parent.Parent.PetDusp3.Visible = false
	ishatch = false
	togglegui(true)
	_G.newTemp(petName)
	_G.newTemp(petName2)
	_G.newTemp(petName3)
end


uis.InputBegan:Connect(function(input)
	local billboardtemp = script.Template
	local clonedtemp = billboardtemp.Cointainer.button
	if input.KeyCode == Enum.KeyCode.E then
		if plr.Character ~= nil and ishatch == false then
			local plrps = plr.Character.HumanoidRootPart.Position
			local nearsetg
			for i,v in pairs(eggs:GetChildren()) do
				for i,v in pairs(eggs:GetChildren()) do
					if nearsetg == nil then
						nearsetg = v
					else
						if (plrps - v.EggMesh.PrimaryPart.Position).Magnitude < (nearsetg.EggMesh.PrimaryPart.Position).Magnitude then
							nearsetg = v
						end
					end
				end
			end
			if plr:DistanceFromCharacter(nearsetg.EggMesh.PrimaryPart.Position) < distance then
				canhatch = true

			else
				canhatch = false
			end
			if canhatch == true then
				if canhatch == true then
					local result = rep: WaitForChild("EggHatchingRemotes"):WaitForChild("hatchserver"):InvokeServer(nearsetg)
					if result ~= nil then
						if not cooldown then
							cooldown = true
							hatch1(result,nearsetg)
							wait(0.1)
							cooldown = false
						end
					end
					
			end
		end
	end
		
	end
	
	if input.KeyCode == Enum.KeyCode.R  then
		if plr.Character ~= nil and ishatch == false then
			local plrps = plr.Character.HumanoidRootPart.Position
			local nearsetg
			for i,v in pairs(eggs:GetChildren()) do
				for i,v in pairs(eggs:GetChildren()) do
					if nearsetg == nil then
						nearsetg = v
					else
						if (plrps - v.EggMesh.PrimaryPart.Position).Magnitude < (nearsetg.EggMesh.PrimaryPart.Position).Magnitude then
							nearsetg = v
						end
					end
				end
			end
			if plr:DistanceFromCharacter(nearsetg.EggMesh.PrimaryPart.Position) < distance then
				canhatch = true

			else
				canhatch = false
			end
			if canhatch == true then
				if canhatch == true then
					local result1 , result2, result3 = rep.EggHatchingRemotes.hatch3pets:InvokeServer(nearsetg)
					if result1 ~= nil and result2 ~= nil and result3 ~= nil then
						if not cooldown then
							cooldown = true
							triplehatch(result1, result2, result3, nearsetg)
							wait(0.1)
							cooldown = false
						end
						
					
					end

				end
			end
		end

	end
end)

for i,v in pairs(script.Parent.Parent.Eggboards:GetChildren()) do
	
	local ebtn = v.Cointainer.button.Open_one
	local rbtn = v.Cointainer.button.Open_three
	
	ebtn.MouseButton1Click:Connect(function()
		if plr.Character ~= nil and ishatch == false then
		
			local nearsetg
			local plrps = plr.Character.HumanoidRootPart.Position
			
			for i,v in pairs(eggs:GetChildren()) do
				for i,v in pairs(eggs:GetChildren()) do
					if nearsetg == nil then
						nearsetg = v
					else
						if (plrps - v.EggMesh.PrimaryPart.Position).Magnitude < (nearsetg.EggMesh.PrimaryPart.Position).Magnitude then
							nearsetg = v
						end
					end
				end
				if plr:DistanceFromCharacter(nearsetg.EggMesh.PrimaryPart.Position) < distance then
					canhatch = true

				else
					canhatch = false
				end
				if canhatch == true then
					
						local result = rep:WaitForChild("EggHatchingRemotes"):WaitForChild("hatchserver"):InvokeServer(nearsetg)
						if result ~= "Cannot hatch" then
							if not cooldown then
								cooldown = true
								triplehatch(result,nearsetg)
								wait(0.1)
								cooldown = false
							end


						end

					end
				end
			end
		
	end)
	
	rbtn.MouseButton1Click:Connect(function()
		if plr.Character ~= nil and ishatch == false then
			local plrps = plr.Character.HumanoidRootPart.Position
			local nearsetg
			for i,v in pairs(eggs:GetChildren()) do
				for i,v in pairs(eggs:GetChildren()) do
					if nearsetg == nil then
						nearsetg = v
					else
						if (plrps - v.EggMesh.PrimaryPart.Position).Magnitude < (nearsetg.EggMesh.PrimaryPart.Position).Magnitude then
							nearsetg = v
						end
					end
				end
			end
			if plr:DistanceFromCharacter(nearsetg.EggMesh.PrimaryPart.Position) < distance then
				canhatch = true

			else
				canhatch = false
			end
			if canhatch == true then
				if canhatch == true then
					local result1 , result2, result3 = rep.EggHatchingRemotes.hatch3pets:InvokeServer(nearsetg)
					if result1 ~= nil and result2 ~= nil and result3 ~= nil then
						if not cooldown then
							cooldown = true
							triplehatch(result1, result2, result3, nearsetg)
							wait(0.1)
							cooldown = false
						end


					end

				end
			end
		end 
	end)
	
end 
1 Like

Can you show a picture of the output when the error happens?

Is this okay video okay? @skippychubby12. Also this only happens when i click the button but when i press “E” on my keyboard it works fine.

it means the object you want the name is nil

Yes, i know but how exactly do you make it not nil?

can you tell me the line where it causes the error?

local function triplehatch(petName,petName2,petName3,egg)
	print(egg.Name)
	togglegui(false)
	--where error occurs
	
	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.PetDusp.petnaem.Text = tostring(petName)
	script.Parent.Parent.PetDusp2.petnaem.Text = tostring(petName2)
	script.Parent.Parent.PetDusp3.petnaem.Text = tostring(petName3)
local rep = game:GetService("ReplicatedStorage")
local runs = game:GetService("RunService")
local model3D = require(rep:WaitForChild("Module3D"))
local tweeny = game:GetService("TweenService")
local uis = game:GetService("UserInputService")

local plr = game.Players.LocalPlayer
local cam = workspace.Camera
local pets = rep:WaitForChild("Pets")
local eggs = workspace:WaitForChild("Nidus")
local distance  = 40

local canhatch = nil
local ishatch = false
local hatch1connect = nil
local cooldown = false
wait(3)

local function animatebilly(billboard , openorclose)
	if openorclose == true then
		tweeny:Create(billboard, TweenInfo.new(0.1),{Size = UDim2.new(15, 0,20, 0)}):Play()
	else
		tweeny:Create(billboard, TweenInfo.new(0.2),{Size = UDim2.new(0,0,0, 0)}):Play()
		wait(.3)
		billboard.Enabled = false
	end
	wait(1)
end

local function togglegui(bool)
	for i,v in pairs(script.Parent.Parent.Parent:GetChildren()) do
		if v.Name ~= "EggSystem" then
			v.Enabled = bool
		end
	end
end



for i,v in pairs(eggs:GetChildren()) do
	local eggpets = pets:FindFirstChild(v.Name)

	if eggpets ~= nil then


		local billboardtemp = script.Template:Clone()
		local container = billboardtemp:WaitForChild("Cointainer")
		local frame = container:WaitForChild("Main_Frame")
		local template = frame:WaitForChild("Template")
		local billboardegg = script.Parent.Parent.Eggboards
		local port = template:WaitForChild("Port")

		billboardtemp.Adornee = v.EggMesh
		billboardtemp.Name = v.Name
		billboardtemp.Enabled = true
		billboardtemp.Parent = billboardegg

		local petz = {}

		for x, pet in pairs(eggpets:GetChildren()) do
			table.insert(petz, pet.Rarity.Value)

		end
		table.sort(petz)

		for i = 1, math.floor(#petz/2) do
			local j = #petz - i + 1
			petz[i], petz[j] = petz[j], petz[i]
		end

		for _,rarity in pairs(petz) do
			for _, pet in pairs(eggpets:GetChildren()) do
				if pet.Rarity.Value == rarity then
					local rarity = pet.Rarity.Value



					local clonedtemp = template:Clone()
					clonedtemp.Name = pet.Name

					clonedtemp.Rarity.Text = tostring(pet.Rarity.Value).."%"
					clonedtemp.Visible = true
					clonedtemp.Parent = frame

					local petmodel = model3D:Attach3D(clonedtemp.Port,pet:Clone())
					petmodel:SetDepthMultiplier(1.2)
					petmodel.Camera.FieldOfView = 5
					petmodel.Visible = true

					runs.RenderStepped:Connect(function()
						petmodel:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(10),0,0))
					end)
					break
				else
					continue
				end
			end
		end



		runs.RenderStepped:Connect(function()
			if plr:DistanceFromCharacter(v.EggMesh.PrimaryPart.Position) < distance then
				if billboardtemp.Name ~= v.Name then
					canhatch = true

					animatebilly(billboardtemp, true)
					billboardtemp.Enabled = true
				else
					canhatch = true

					animatebilly(billboardtemp, true)
					billboardtemp.Enabled = true

				end
			else
				animatebilly(billboardtemp, false)

				canhatch = false
			end

		end)
	end
end

local function hatch1(petName,egg)
	print(petName)
	togglegui(false)

	local pet = pets[egg.Name]:FindFirstChild(petName):Clone()
	local eggmesh = egg:FindFirstChild("EggMesh"):Clone()
	ishatch = true

	script.Parent.Parent.PetDusp.petnaem.Text = tostring(petName)
	print(egg.Name)
	for i,v in pairs(eggmesh:GetChildren()) do
		if v:isA("BasePart") then
			v.Anchored = true
			v.CanCollide = false
		end
	end
	hatch1connect = runs.RenderStepped:Connect(function()
		local cf = CFrame.new(0, 0,-eggmesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(math.sin(time() *4)*2,math.sin(time() *4) *2,math.sin(time() *4) * 2)
		eggmesh:SetPrimaryPartCFrame(cam.CFrame * cf)
	end)
	eggmesh.Parent = cam
	wait(3)
	for i,v in pairs(eggmesh:GetChildren()) do
		if v:isA("BasePart") then
			tweeny:Create(v, TweenInfo.new(0.3),{Transparency = 1}):Play()
		end
	end
	wait(0.3)
	hatch1connect:Disconnect()
	eggmesh:Destroy()
	script.Parent.Parent.PetDusp.Visible = true

	local petmodel = model3D:Attach3D(script.Parent.Parent.PetDusp,pet)
	petmodel:SetDepthMultiplier(1.2)
	petmodel.Camera.FieldOfView = 5
	petmodel.Visible = true

	runs.RenderStepped:Connect(function()
		petmodel:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
	end)
	wait(3)
	tweeny:Create(script.Parent.Parent.PetDusp:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
	wait(0.5)
	for i, v in pairs(script.Parent.Parent.PetDusp:GetDescendants()) do
		if v:IsA("ViewportFrame") then
			v:Destroy()
			script.Parent.Parent.PetDusp.Visible = true
		end
	end
	script.Parent.Parent.PetDusp.Visible = false

	togglegui(true)
	_G.newTemp(petName)
end

local function triplehatch(petName,petName2,petName3,egg)
	print(egg.Name)
	togglegui(false)
	--where error occurs

	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.PetDusp.petnaem.Text = tostring(petName)
	script.Parent.Parent.PetDusp2.petnaem.Text = tostring(petName2)
	script.Parent.Parent.PetDusp3.petnaem.Text = tostring(petName3)
	ishatch = 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


	hatch1connect = runs.RenderStepped:Connect(function()
		local cf = CFrame.new(0, 0,-eggmesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(math.sin(time() *4)*2,math.sin(time() *4) *2,math.sin(time() *4) * 2)
		eggmesh:SetPrimaryPartCFrame(cam.CFrame * cf)

		local cf2 = CFrame.new(6, 0,-eggmesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(math.sin(time() *4)*2,math.sin(time() *4) *2,math.sin(time() *4) * 2)
		eggmesh2:SetPrimaryPartCFrame(cam.CFrame * cf2)

		local cf3 = CFrame.new(-6, 0,-eggmesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(math.sin(time() *4)*2,math.sin(time() *4) *2,math.sin(time() *4) * 2)
		eggmesh3:SetPrimaryPartCFrame(cam.CFrame * cf3)
	end)
	eggmesh.Parent = cam
	eggmesh2.Parent = cam
	eggmesh3.Parent = cam
	wait(3)
	ishatch = false
	for i,v in pairs(eggmesh:GetChildren()) do
		if v:isA("BasePart") then
			tweeny:Create(v, TweenInfo.new(0.3),{Transparency = 1}):Play()
		end
	end

	for i,v in pairs(eggmesh2:GetChildren()) do
		if v:isA("BasePart") then
			tweeny:Create(v, TweenInfo.new(0.3),{Transparency = 1}):Play()
		end
	end

	for i,v in pairs(eggmesh3:GetChildren()) do
		if v:isA("BasePart") then
			tweeny:Create(v, TweenInfo.new(0.3),{Transparency = 1}):Play()
		end
	end
	wait(0.3)
	hatch1connect:Disconnect()
	eggmesh:Destroy()
	eggmesh2:Destroy()
	eggmesh3:Destroy()
	script.Parent.Parent.PetDusp.Visible = true
	script.Parent.Parent.PetDusp2.Visible = true
	script.Parent.Parent.PetDusp3.Visible = true

	local petmodel = model3D:Attach3D(script.Parent.Parent.PetDusp,pet)
	petmodel:SetDepthMultiplier(1.2)
	petmodel.Camera.FieldOfView = 5
	petmodel.Visible = true

	local petmodel2 = model3D:Attach3D(script.Parent.Parent.PetDusp2,pet2)
	petmodel2:SetDepthMultiplier(1.2)
	petmodel2.Camera.FieldOfView = 5
	petmodel2.Visible = true

	local petmodel3 = model3D:Attach3D(script.Parent.Parent.PetDusp3,pet3)
	petmodel3:SetDepthMultiplier(1.2)
	petmodel3.Camera.FieldOfView = 5
	petmodel3.Visible = true


	runs.RenderStepped:Connect(function()
		petmodel:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
		petmodel2:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
		petmodel3:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
	end)


	wait(3)
	tweeny:Create(script.Parent.Parent.PetDusp:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
	tweeny:Create(script.Parent.Parent.PetDusp2:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
	tweeny:Create(script.Parent.Parent.PetDusp3:FindFirstChildOfClass("ViewportFrame"), TweenInfo.new(0.5), {ImageTransparency = 1}):Play()

	wait(0.5)
	for i, v in pairs(script.Parent.Parent.PetDusp:GetDescendants()) do
		if v:IsA("ViewportFrame") then
			v:Destroy()
			script.Parent.Parent.PetDusp.Visible = true
		end
	end

	for i, v in pairs(script.Parent.Parent.PetDusp2:GetDescendants()) do
		if v:IsA("ViewportFrame") then
			v:Destroy()
			script.Parent.Parent.PetDusp2.Visible = true
		end
	end

	for i, v in pairs(script.Parent.Parent.PetDusp3:GetDescendants()) do
		if v:IsA("ViewportFrame") then
			v:Destroy()
			script.Parent.Parent.PetDusp3.Visible = true
		end
	end
	script.Parent.Parent.PetDusp.Visible = false
	script.Parent.Parent.PetDusp2.Visible = false
	script.Parent.Parent.PetDusp3.Visible = false
	ishatch = false
	togglegui(true)
	_G.newTemp(petName)
	_G.newTemp(petName2)
	_G.newTemp(petName3)
end


uis.InputBegan:Connect(function(input)
	local billboardtemp = script.Template
	local clonedtemp = billboardtemp.Cointainer.button
	if input.KeyCode == Enum.KeyCode.E then
		if plr.Character ~= nil and ishatch == false then
			local plrps = plr.Character.HumanoidRootPart.Position
			local nearsetg
			for i,v in pairs(eggs:GetChildren()) do
				for i,v in pairs(eggs:GetChildren()) do
					if nearsetg == workspace then
						nearsetg = v
					else
						if (plrps - v.EggMesh.PrimaryPart.Position).Magnitude < (nearsetg.EggMesh.PrimaryPart.Position).Magnitude then
							nearsetg = v
						end
					end
				end
			end
			if plr:DistanceFromCharacter(nearsetg.EggMesh.PrimaryPart.Position) < distance then
				canhatch = true

			else
				canhatch = false
			end
			if canhatch == true then
				if canhatch == true then
					local result = rep: WaitForChild("EggHatchingRemotes"):WaitForChild("hatchserver"):InvokeServer(nearsetg)
					if result ~= nil then
						if not cooldown then
							cooldown = true
							hatch1(result,nearsetg)
							wait(0.1)
							cooldown = false
						end
					end

				end
			end
		end

	end

	if input.KeyCode == Enum.KeyCode.R  then
		if plr.Character ~= nil and ishatch == false then
			local plrps = plr.Character.HumanoidRootPart.Position
			local nearsetg
			for i,v in pairs(eggs:GetChildren()) do
				for i,v in pairs(eggs:GetChildren()) do
					if nearsetg == workspace then
						nearsetg = v
					else
						if (plrps - v.EggMesh.PrimaryPart.Position).Magnitude < (nearsetg.EggMesh.PrimaryPart.Position).Magnitude then
							nearsetg = v
						end
					end
				end
			end
			if plr:DistanceFromCharacter(nearsetg.EggMesh.PrimaryPart.Position) < distance then
				canhatch = true

			else
				canhatch = false
			end
			if canhatch == true then
				if canhatch == true then
					local result1 , result2, result3 = rep.EggHatchingRemotes.hatch3pets:InvokeServer(nearsetg)
					if result1 ~= nil and result2 ~= nil and result3 ~= nil then
						if not cooldown then
							cooldown = true
							triplehatch(result1, result2, result3, nearsetg)
							wait(0.1)
							cooldown = false
						end


					end

				end
			end
		end

	end
end)

for i,v in pairs(script.Parent.Parent.Eggboards:GetChildren()) do

	local ebtn = v.Cointainer.button.Open_one
	local rbtn = v.Cointainer.button.Open_three

	ebtn.MouseButton1Click:Connect(function()
		if plr.Character ~= nil and ishatch == false then

			local nearsetg = workspace
			local plrps = plr.Character.HumanoidRootPart.Position

			for i,v in pairs(eggs:GetChildren()) do
				for i,v in pairs(eggs:GetChildren()) do
					if nearsetg == workspace then
						nearsetg = v
					else
						if (plrps - v.EggMesh.PrimaryPart.Position).Magnitude < (nearsetg.EggMesh.PrimaryPart.Position).Magnitude then
							nearsetg = v
						end
					end
				end
				if plr:DistanceFromCharacter(nearsetg.EggMesh.PrimaryPart.Position) < distance then
					canhatch = true

				else
					canhatch = false
				end
				if canhatch == true then

					local result = rep:WaitForChild("EggHatchingRemotes"):WaitForChild("hatchserver"):InvokeServer(nearsetg)
					if result ~= "Cannot hatch" then
						if not cooldown then
							cooldown = true
							triplehatch(result,nearsetg)
							wait(0.1)
							cooldown = false
						end


					end

				end
			end
		end

	end)

	rbtn.MouseButton1Click:Connect(function()
		if plr.Character ~= nil and ishatch == false then
			local plrps = plr.Character.HumanoidRootPart.Position
			local nearsetg
			for i,v in pairs(eggs:GetChildren()) do
				for i,v in pairs(eggs:GetChildren()) do
					if workspace then
						nearsetg = v
					else
						if (plrps - v.EggMesh.PrimaryPart.Position).Magnitude < (nearsetg.EggMesh.PrimaryPart.Position).Magnitude then
							nearsetg = v
						end
					end
				end
			end
			if plr:DistanceFromCharacter(nearsetg.EggMesh.PrimaryPart.Position) < distance then
				canhatch = true

			else
				canhatch = false
			end
			if canhatch == true then
				if canhatch == true then
					local result1 , result2, result3 = rep.EggHatchingRemotes.hatch3pets:InvokeServer(nearsetg)
					if result1 ~= nil and result2 ~= nil and result3 ~= nil then
						if not cooldown then
							cooldown = true
							triplehatch(result1, result2, result3, nearsetg)
							wait(0.1)
							cooldown = false
						end


					end

				end
			end
		end 
	end)
end

try dis

  Players.itzmerose_12.PlayerGui.EggSystem.Clientscripts.Hatch_Client:333: attempt to index nil with 'EggMesh'

appears on these lines:

if (plrps - v.EggMesh.PrimaryPart.Position).Magnitude < (nearsetg.EggMesh.PrimaryPart.Position).Magnitude then
							nearsetg = v
						end

that means the directory to eggmesh is wrong do

if (plrps - v.EggMesh.PrimaryPart.Position).Magnitude < (nearsetg:FindFirstChild("EggMesh",true).PrimaryPart.Position).Magnitude then
							nearsetg = v
						end

now it says the error we started with in the same area

Hello, it shows this error

 Players.itzmerose_12.PlayerGui.EggSystem.Clientscripts.Hatch_Client:332: attempt to index nil with 'FindFirstChild'

and this too

Players.itzmerose_12.PlayerGui.EggSystem.Clientscripts.Hatch_Client:185: attempt to index nil with 'Name'

where the first error apprears:

	if (plrps - v.EggMesh.PrimaryPart.Position).Magnitude < (nearsetg:FindFirstChild("EggMesh",true).PrimaryPart.Position).Magnitude then
							nearsetg = v
						end

Second error :

local function triplehatch(petName,petName2,petName3,egg)
	togglegui(false)
	--where error occurs

	local pet = pets[egg.Name]:FindFirstChild(petName):Clone()
	local pet2 = pets[egg.Name]:FindFirstChild(petName2):Clone()
	local pet3 = pets[egg.Name]:FindFirstChild(petName3):Clone()

so that means nearsetg is nil

so should i make its value the value of what?

should i make it’s value the value of egg or what?

ok so i made an if condition and i made if its value is nil then its value is v but now nothing works

uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh wait mmmmmmmmm check ur entire code for nearsetg and if at first where u set local nearsetg change dat to smthing

This error pops up now :frowning:

Players.itzmerose_12.PlayerGui.EggSystem.Clientscripts.Hatch_Client:185: attempt to index nil with 'Name'

on this line

local pet = pets[egg.Name]:FindFirstChild(petName):Clone()

It means that egg isn’t an instance with name attribute. Try printing egg.