Pets Aren't Visible in Inventory

I have an issue where I can’t see my pets inside of my inventory. I already have a datastore where the pets save but the pets wont show up.
I have already tried debugging but I couldn’t find the issue. I’ll give a few hundred robux for anyone who can solve it for me, I’ve been stuck on it for a few days now.

In this picture my pets/storage/equipped saves but the pets are not visible!
petinvetoryfix

-- My Inventory Handler that loads the pets into the inventory.
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

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
2 Likes

No one will be able to help if you don’t supply the scripts.

Scripts will be necessary since this is something you have coded yourself and not part of the API.

Im new to dev fourm sorry, ill post them now. Do you need my datastore and inventory handler?

Preferably the script where you try to load the pets. Both may be helpful too though.

Just posted my inventory holder.

When you test the game could you send a screenshot of your gui hierarchy in explorer?

Not sure what you mean, sorry. Where do I locate that?

When you press play could you send a screenshot of it in the explorer (the thing that by default is on the right side of the screen showing things like Workspace and StarterGui).

Edit: So go to Players > Username > PlayerGui and take a screenshot from there.

So you want a picture of the gui’s inside of my StarterGui?

Sorry, from PlayerGui. Which is located inside of the Player.

playergui

My fault again, I meant could you send a screenshot of the Inventory gui and it’s children.

This? Sorry if im being difficult.
petinvvv

Your not being difficult. A screenshot of where the pets would be located in the gui if it was working.

petinventory

It would be in this area, im going to assume.

image

it would be in the gray frame. The black box, equips, crafts or unequips the pet.

You have this which creates the gui objects for the pets, but I cannot see a part which actually adds a child to Pets which means this might never run which might be why they don’t show up. Apologies if I missed something.

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)

Oh I see. What would the right solution be for this?