Egg Hatching System | NOT HATCHING (FIXED) but another problem the inventory is not showing the pets or storage

Hello! My inventory is not showing the pet or storage.
Here the script

local Player = game.Players.LocalPlayer
local Pets = Player:WaitForChild("Pets")
local Data = Player:WaitForChild("Data")
local UIelements = Player.PlayerGui:WaitForChild("UIelements")
local RS = game.ReplicatedStorage
local InventoryFrame = script.Parent.MainFrame.Inventory
local EquippedText = script.Parent.MainFrame.EquippedDisplay.TextLabel
local StorageText = script.Parent.MainFrame.StorageDisplay.TextLabel

function getLevel(totalXP)
	local Increment = 0
	local RequiredXP = 100
	for i = 0, RS.Pets.Settings.MaxPetLevel.Value do
		RequiredXP = 100 + (25*i)
		if totalXP >= (100*i) + Increment then
			if i ~= RS.Pets.Settings.MaxPetLevel.Value then
				if totalXP < ((100*i) + Increment) + RequiredXP then
					return i
				end
			else
				return i
			end
		end
		Increment = Increment+(i*25)
	end
end

function GetFolderFromPetID(PetID)
	for i,v in pairs(Player.Pets:GetChildren()) do
		if v.PetID.Value == PetID then
			return v
		end
	end
	return nil
end

function getLayoutOrder(PetID)
	local Folder = GetFolderFromPetID(PetID)
	local RarityNumber = RS.Pets.Rarities:FindFirstChild(RS.Pets.Models:FindFirstChild(Folder.Name).Settings.Rarity.Value).Order.Value
	local TotalLevels = RS.Pets.Settings.MaxPetLevel.Value
	local PetLevel = getLevel(Folder.TotalXP.Value)
	local Pets = {}
	local Counter = 0
	for i,v in pairs(RS.Pets.Models:GetChildren()) do
		Pets[#Pets + 1] = v
	end
	table.sort(Pets,function(a,b)
		return a:GetFullName() < b:GetFullName()
	end)
	for i,v in pairs(Pets) do
		if Folder.Equipped.Value == true then
			if Folder.Name == v.Name then
				return TotalLevels * #Pets * (#RS.Pets.Rarities:GetChildren() - RarityNumber) + (Counter * TotalLevels) + (TotalLevels - PetLevel)
			end
		else
			if Folder.Name == v.Name then
				return (#Pets * #RS.Pets.Rarities:GetChildren() * TotalLevels) + TotalLevels * #Pets * (#RS.Pets.Rarities:GetChildren() - RarityNumber) + (Counter * TotalLevels) + (TotalLevels - PetLevel)
			end
		end
		Counter = Counter + 1
	end
end

function newUI(PetFolder)
	local UI = UIelements.PetTemplate:Clone()
	local RSfolder = RS.Pets.Models:FindFirstChild(PetFolder.Name)
	local ModelClone = RSfolder:FindFirstChild(PetFolder:WaitForChild("Type").Value):Clone()
	local Gradient1 = RS.Pets.Rarities:FindFirstChild(RSfolder.Settings.Rarity.Value).Color.Value
	local Gradient2 = Color3.new(Gradient1.R - 150/255, Gradient1.G - 150/255, Gradient1.B - 150/255)
	local Camera = Instance.new("Camera", UI.PetView)
	local Pos = ModelClone.PrimaryPart.Position
	UI.PetID.Value = PetFolder:WaitForChild("PetID").Value
	UI.Name = PetFolder.Name
	UI.LevelLabel.Text = "Lvl. " .. getLevel(PetFolder:WaitForChild("TotalXP").Value)
	UI.Gradient.UIGradient.Color = ColorSequence.new(Gradient1, Gradient2)
	UI.PetView.CurrentCamera = Camera
	ModelClone.Parent = UI.PetView
	Camera.CFrame = CFrame.new(Vector3.new(Pos.X + 2.25, Pos.Y, Pos.Z + 1), Pos)
	UI.Parent = InventoryFrame
	InventoryFrame.CanvasSize = UDim2.new(0, 0, 0, InventoryFrame.UIGridLayout.AbsoluteContentSize.Y + 200)
	if PetFolder.Equipped.Value == true then 
		UI.EquipMarker.Visible = true
	else
		UI.EquipMarker.Visible = false
	end
	PetFolder:WaitForChild("TotalXP"):GetPropertyChangedSignal("Value"):Connect(function()
		UI.LevelLabel.Text = "Lvl. " .. getLevel(PetFolder:WaitForChild("TotalXP").Value)
	end)
	for i,v in pairs(InventoryFrame:GetChildren()) do
		if not v:IsA("UIGridLayout") then
			v.LayoutOrder = getLayoutOrder(v.PetID.Value)
		end
	end
end

for i,v in pairs(Pets:GetChildren()) do
	newUI(v)
end

Pets.ChildAdded:Connect(function(PetFolder)
	local Equipped = 0
	for i,v in pairs(Pets:GetChildren()) do
		if v:WaitForChild("Equipped").Value == true then
			Equipped = Equipped + 1
		end
	end	
	StorageText.Text = #Pets:GetChildren() .. "/" .. Data.MaxStorage.Value
	EquippedText.Text = Equipped .. "/" .. Data.MaxEquip.Value
	newUI(PetFolder)
end)

Pets.ChildRemoved:Connect(function(PetFolder)
	for i,v in pairs(InventoryFrame:GetChildren()) do
		if not v:IsA("UIGridLayout") then
			if v.PetID.Value == PetFolder.PetID.Value then
				v:Destroy()
			end
		end
	end
	local Equipped = 0
	for i,v in pairs(Pets:GetChildren()) do
		if v.Equipped.Value == true then
			Equipped = Equipped + 1
		end
	end	
	StorageText.Text = #Pets:GetChildren() .. "/" .. Data.MaxStorage.Value
	EquippedText.Text = Equipped .. "/" .. Data.MaxEquip.Value
end)

InventoryFrame.ChildAdded:Connect(function()
	InventoryFrame.CanvasSize = UDim2.new(0, 0, 0, InventoryFrame.UIGridLayout.AbsoluteContentSize.Y + 200)
end)

I’m not sure if you already have implemented the randomizing egg because when I search for math.random keywords appears for no results, are you using a different way to make the egg hatching system

Your script also doesn’t look very effective though because you are using for loops to make linear animations…

That’s what I know, I can’t fully understand your script and make changes on every bit but I hope this helps!

Also next time explain your issue better because “The egg wont hatch” will sounds confusing maybe add a little more details in your issue to explain better?

When I press E the egg won’t hatch.
The egg worked before but is currently broken.
Also this is my old scripter work so idk how to use math.random.

can you reformat you code because i cant see it now

that is not what i meant

--[EGGS MODULE]
local Eggs = {
    Basic = {
        Cost = 250,
        Currency = “Clicks”,
        ProductID = nil,
        Pets = {
            [1] = {Name = “Dog”, Type = “Normal”, Rarity = 90, Secret = false},
            [2] = {Name = “Cat”, Type = “Normal”, Rarity = 80, Secret = false},
            [3] = {Name = “Bunny”, Type = “Normal”, Rarity = 70, Secret = false},
            [4] = {Name = “Bear”, Type = “Normal”, Rarity = 60, Secret = false},
            [5] = {Name = “Fox”, Type = “Normal”, Rarity = 50, Secret = false},
[6] = {Name = “Bull”, Type = “Normal”, Rarity = 40, Secret = false},
}
},
Epic = {
Cost = 10000,
Currency = “Clicks”,
ProductID = nil,
Pets = {
[1] = {Name = “Alien”, Type = “Normal”, Rarity = 90, Secret = false},
[2] = {Name = “Water Dragon”, Type = “Normal”, Rarity = 80, Secret = false},
[3] = {Name = “Star”, Type = “Normal”, Rarity = 70, Secret = false},
[4] = {Name = “Lizard”, Type = “Normal”, Rarity = 60, Secret = false},
[5] = {Name = “Deer”, Type = “Normal”, Rarity = 50, Secret = false},
[6] = {Name = “Rabbit”, Type = “Normal”, Rarity = 40, Secret = false},
[7] = {Name = “Dragon”, Type = “Normal”, Rarity = 30, Secret = false},
}
},
Hydra = {
Cost = 350000,
Currency = “Clicks”,
ProductID = nil,
Pets = {
[1] = {Name = “Varan”, Type = “Normal”, Rarity = 30, Secret = false},
[2] = {Name = “Helios”, Type = “Normal”, Rarity = 20, Secret = false},
[3] = {Name = “Gloxcinia”, Type = “Normal”, Rarity = 18, Secret = false},
[4] = {Name = “Sand Dweller”, Type = “Normal”, Rarity = 15, Secret = false},
[5] = {Name = “Hyperion”, Type = “Normal”, Rarity = 10, Secret = false},
[6] = {Name = “Aether”, Type = “Normal”, Rarity = 5, Secret = false},
[7] = {Name = “Primus”, Type = “Normal”, Rarity = 1, Secret = false},
}

},
Codes = {
	Cost = 350000,
	Currency = "Clicks",
	ProductID = nil,
	Pets = {
		[1] = {Name = "Tofuu", Type = "Normal", Rarity = 20, Secret = false},
		[2] = {Name = "Roblerom", Type = "Normal", Rarity = 20, Secret = false},
		[3] = {Name = "ToadBoiGaming", Type = "Normal", Rarity = 18, Secret = false},
		[4] = {Name = "JeeffBlox", Type = "Normal", Rarity = 15, Secret = false},
		[5] = {Name = "Flamingo", Type = "Normal", Rarity = 10, Secret = false},
		[6] = {Name = "FernandaaGames", Type = "Normal", Rarity = 5, Secret = false},
		[7] = {Name = "Russo", Type = "Normal", Rarity = 1, Secret = false},
		[8] = {Name = "Noob", Type = "Normal", Rarity = 1, Secret = false},
	}

},
GrasslandTemplate  = {
	Cost = 350000,
	Currency = "Clicks",
	ProductID = nil,
	Pets = {
		[1] = {Name = "LavaHeart", Type = "Normal", Rarity = 60, Secret = false},
	}>
},
}
return Eggs

not many changes


--VIEWHANDLER
local RS = game.ReplicatedStorage
local Config = require(RS.Pets.Eggs)
local Models = RS.Pets.Models
local CurrentTarget = script.Parent.CurrentTarget
local CostLabel = script.Parent.CostLabel
local PetsFrame = script.Parent.PetsFrame

function resetFrame()
for _,Slot in pairs(PetsFrame:GetChildren()) do
if Slot.Name ~= “Shadow” then
for _,Item in pairs(Slot.PetView:GetChildren()) do
Item:Destroy()
end
Slot.Percentage.Text = “”
Slot.Rarity.Text = “”
Slot.ImageColor3 = Color3.fromRGB(25,25,25)
end
end
end

CurrentTarget:GetPropertyChangedSignal(“Value”):Connect(function()
if CurrentTarget.Value ~= “None” then
local Egg = Config[CurrentTarget.Value]
local Cost = Egg.Cost
local Currency = Egg.Currency
local CurrencyImage = RS.Pets.Settings:FindFirstChild(Currency…“Image”).Value
local Counter = 0
local Pets = {}
for _,Pet in pairs(Egg.Pets) do
Pets[#Pets + 1] = {Name = Pet.Name, Type = Pet.Type, Rarity = Pet.Rarity, Secret = Pet.Secret}
Counter = Counter + Pet.Rarity
end
CostLabel.CurrencyImage.Image = CurrencyImage
CostLabel.TextLabel.Text = Cost
table.sort(Pets,
function(a,b)
return a.Rarity > b.Rarity
end
)
if Currency ~= “R$” then
script.Parent.BuyButtonR.Visible = true
script.Parent.BuyButtonT.Visible = true
script.Parent.BuyButtonE.Size = script.Parent.BuyButtonR.Size
else
script.Parent.BuyButtonR.Visible = false
script.Parent.BuyButtonT.Visible = false
script.Parent.BuyButtonE.Size = script.Parent.CostLabel.Size
end
resetFrame()
for i,v in pairs(Pets) do
if v.Secret == false then
local PetName = v.Name
local PetModel = Models:FindFirstChild(PetName):FindFirstChild(v.Type):Clone()
local Slot = PetsFrame:FindFirstChild(“Slot”…i)
local Viewport = Slot.PetView
local Percentage = math.floor((v.Rarity/Counter)*10000)/100
local Rarity = Models:FindFirstChild(PetName).Settings.Rarity.Value
local RarityColor = RS.Pets.Rarities:FindFirstChild(Rarity).Color.Value
local Camera = Instance.new(“Camera”, Viewport)
local Pos = Vector3.new(0,0,0)
Viewport.CurrentCamera = Camera
PetModel:SetPrimaryPartCFrame(CFrame.new(Pos))
PetModel.Parent = Viewport
Slot.Percentage.Text = Percentage…"%"
Slot.Rarity.Text = Rarity
Slot.Rarity.TextColor3 = RarityColor
Slot.ImageColor3 = Color3.fromRGB(55,55,55)
spawn(function()
local rot = 180
while wait() do
if PetModel.Parent ~= nil then
Camera.CFrame = CFrame.Angles(0, math.rad(rot), 0) * CFrame.new(Pos + Vector3.new(0,0,3),Pos + Vector3.new(0,0,0))
rot = rot + 1
else
break
end
end
end)
end
end
else
resetFrame()
end
end)

is there an error,where is the error?

local PetModel = Models:FindFirstChild(PetName):FindFirstChild(v.Type):Clone()

That’s this line of code here.

Know how to fix this?
ef
ef
d
ger
ge
btrg

local Player = game.Players.LocalPlayer
local Pets = Player:WaitForChild("Pets")
local Data = Player:WaitForChild("Data")
local UIelements = Player.PlayerGui:WaitForChild("UIelements")
local RS = game.ReplicatedStorage
local InventoryFrame = script.Parent.MainFrame.Inventory
local EquippedText = script.Parent.MainFrame.EquippedDisplay.TextLabel
local StorageText = script.Parent.MainFrame.StorageDisplay.TextLabel

function getLevel(totalXP)
	local Increment = 0
	local RequiredXP = 100
	for i = 0, RS.Pets.Settings.MaxPetLevel.Value do
		RequiredXP = 100 + (25*i)
		if totalXP >= (100*i) + Increment then
			if i ~= RS.Pets.Settings.MaxPetLevel.Value then
				if totalXP < ((100*i) + Increment) + RequiredXP then
					return i
				end
			else
				return i
			end
		end
		Increment = Increment+(i*25)
	end
end

function GetFolderFromPetID(PetID)
	for i,v in pairs(Player.Pets:GetChildren()) do
		if v.PetID.Value == PetID then
			return v
		end
	end
	return nil
end

function getLayoutOrder(PetID)
	local Folder = GetFolderFromPetID(PetID)
	local RarityNumber = RS.Pets.Rarities:FindFirstChild(RS.Pets.Models:FindFirstChild(Folder.Name).Settings.Rarity.Value).Order.Value
	local TotalLevels = RS.Pets.Settings.MaxPetLevel.Value
	local PetLevel = getLevel(Folder.TotalXP.Value)
	local Pets = {}
	local Counter = 0
	for i,v in pairs(RS.Pets.Models:GetChildren()) do
		Pets[#Pets + 1] = v
	end
	table.sort(Pets,function(a,b)
		return a:GetFullName() < b:GetFullName()
	end)
	for i,v in pairs(Pets) do
		if Folder.Equipped.Value == true then
			if Folder.Name == v.Name then
				return TotalLevels * #Pets * (#RS.Pets.Rarities:GetChildren() - RarityNumber) + (Counter * TotalLevels) + (TotalLevels - PetLevel)
			end
		else
			if Folder.Name == v.Name then
				return (#Pets * #RS.Pets.Rarities:GetChildren() * TotalLevels) + TotalLevels * #Pets * (#RS.Pets.Rarities:GetChildren() - RarityNumber) + (Counter * TotalLevels) + (TotalLevels - PetLevel)
			end
		end
		Counter = Counter + 1
	end
end

function newUI(PetFolder)
	local UI = UIelements.PetTemplate:Clone()
	local RSfolder = RS.Pets.Models:FindFirstChild(PetFolder.Name)
	local ModelClone = RSfolder:FindFirstChild(PetFolder:WaitForChild("Type").Value):Clone()
	local Gradient1 = RS.Pets.Rarities:FindFirstChild(RSfolder.Settings.Rarity.Value).Color.Value
	local Gradient2 = Color3.new(Gradient1.R - 150/255, Gradient1.G - 150/255, Gradient1.B - 150/255)
	local Camera = Instance.new("Camera", UI.PetView)
	local Pos = ModelClone.PrimaryPart.Position
	UI.PetID.Value = PetFolder:WaitForChild("PetID").Value
	UI.Name = PetFolder.Name
	UI.LevelLabel.Text = "Lvl. " .. getLevel(PetFolder:WaitForChild("TotalXP").Value)
	UI.Gradient.UIGradient.Color = ColorSequence.new(Gradient1, Gradient2)
	UI.PetView.CurrentCamera = Camera
	ModelClone.Parent = UI.PetView
	Camera.CFrame = CFrame.new(Vector3.new(Pos.X + 2.25, Pos.Y, Pos.Z + 1), Pos)
	UI.Parent = InventoryFrame
	InventoryFrame.CanvasSize = UDim2.new(0, 0, 0, InventoryFrame.UIGridLayout.AbsoluteContentSize.Y + 200)
	if PetFolder.Equipped.Value == true then 
		UI.EquipMarker.Visible = true
	else
		UI.EquipMarker.Visible = false
	end
	PetFolder:WaitForChild("TotalXP"):GetPropertyChangedSignal("Value"):Connect(function()
		UI.LevelLabel.Text = "Lvl. " .. getLevel(PetFolder:WaitForChild("TotalXP").Value)
	end)
	for i,v in pairs(InventoryFrame:GetChildren()) do
		if not v:IsA("UIGridLayout") then
			v.LayoutOrder = getLayoutOrder(v.PetID.Value)
		end
	end
end

for i,v in pairs(Pets:GetChildren()) do
	newUI(v)
end

Pets.ChildAdded:Connect(function(PetFolder)
	local Equipped = 0
	for i,v in pairs(Pets:GetChildren()) do
		if v:WaitForChild("Equipped").Value == true then
			Equipped = Equipped + 1
		end
	end	
	StorageText.Text = #Pets:GetChildren() .. "/" .. Data.MaxStorage.Value
	EquippedText.Text = Equipped .. "/" .. Data.MaxEquip.Value
	newUI(PetFolder)
end)

Pets.ChildRemoved:Connect(function(PetFolder)
	for i,v in pairs(InventoryFrame:GetChildren()) do
		if not v:IsA("UIGridLayout") then
			if v.PetID.Value == PetFolder.PetID.Value then
				v:Destroy()
			end
		end
	end
	local Equipped = 0
	for i,v in pairs(Pets:GetChildren()) do
		if v.Equipped.Value == true then
			Equipped = Equipped + 1
		end
	end	
	StorageText.Text = #Pets:GetChildren() .. "/" .. Data.MaxStorage.Value
	EquippedText.Text = Equipped .. "/" .. Data.MaxEquip.Value
end)

InventoryFrame.ChildAdded:Connect(function()
	InventoryFrame.CanvasSize = UDim2.new(0, 0, 0, InventoryFrame.UIGridLayout.AbsoluteContentSize.Y + 200)
end)

InventoryFrame.ChildRemoved:Connect(function()
	InventoryFrame.CanvasSize = UDim2.new(0, 0, 0, InventoryFrame.UIGridLayout.AbsoluteContentSize.Y + 200)
end)

-- Text Tools

local Equipped = 0

for i,v in pairs(Pets:GetChildren()) do
	if v.Equipped.Value == true then
		Equipped = Equipped + 1
	end
end

Data.MaxStorage:GetPropertyChangedSignal("Value"):Connect(function()
	StorageText.Text = #Pets:GetChildren() .. "/" .. Data.MaxStorage.Value
end)

Data.MaxEquip:GetPropertyChangedSignal("Value"):Connect(function()
	EquippedText.Text = Equipped .. "/" .. Data.MaxEquip.Value
end)

StorageText.Text = #Pets:GetChildren() .. "/" .. Data.MaxStorage.Value
EquippedText.Text = Equipped .. "/" .. Data.MaxEquip.Value

Are those all the errors which appear?

This means that the PrimaryPart property of the “ModelClone” which is a clone of the model is empty/undefined. Whatever instance RSfolder:FindFirstChild(PetFolder:WaitForChild("Type").Value) this code is referencing you need to define its PrimaryPart property with some part.

yes
d
ad
sd
edesdddasdes
SC

DF
F
df