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!
-- 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