Hello, my name is Rizzy. I’m a new developer on roblox and I have come up onto an issue. Whenever I go into the pet inventory, the image of the pet doesn’t show up and makes the image of the pet into RED. I’ve already tried debugging and haven’t found the solution. Any help would be amazing.
Here’s an image of my issue. As you can see all the pets on the right are red instead of displaying the actual pet.
Here’s my inventory handler:
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
local PlayerPets = workspace.PlayerPets:FindFirstChild(Player.Name)
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 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.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)
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