The Pets Aren't Visible Inside the Inventory

Hi, im new to coding/developing in general. I’m trying to create a pet inventory system where it will save inside of my inventory. I’ve tried everything that I’ve possibly could’ve done myself.

Whenever I open an Egg, the pet appears inside of the inventory and saves. Whenever, I rejoin the game the pet saves inside of the inventory but I can’t see it inside of the inventory. I can’t unequip, equip it or anything.

I’m not 100% sure if its my datastore or my Inventory Handler or something else it might be.
If you need anymore information please let me know and ill post it!

petinvhelp
– In this image it shows the 12 eggs that I opened and that I have 10 pets equipped, but their not visible inside of my inventory.

-- Here's my pet inventory handler 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

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

I’m not asure but try debugging it.

Sadly I did debug it and there was no issues. Is it possible that the ui zindex or something else is the problem?

1 Like