Greetings! Pet icons in my inventory UI aren’t loading. The IDs are valid (they work on SurfaceGuis), but for some reason, they don’t appear inventory. Thanks in advance!
for i, pet in ipairs(pets) do
local btn = Instance.new("ImageButton", scrollFrame)
btn.Name = pet.Name
btn.Size = UDim2.new(0, bSize.X, 0, bSize.Y)
local col, row = (i - 1) % buttonsPerRow, math.floor((i - 1) / buttonsPerRow)
btn.Position = UDim2.new(0, col * (bSize.X + pad) + 5, 0, 10 + (row * (bSize.Y + pad)))
btn.BackgroundColor3 = Color3.fromRGB(45, 45, 45)
btn.ScaleType = Enum.ScaleType.Fit
btn.ZIndex = 5
local function refreshImg()
btn.Image = pet:GetAttribute("Image") or ""
end
refreshImg()
pet:GetAttributeChangedSignal("Image"):Connect(refreshImg)
local stroke = Instance.new("UIStroke", btn)
stroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
Instance.new("UICorner", btn)
local function refreshStyle()
local isEq = pet:GetAttribute("IsEquipped")
local rarityCol = pet:GetAttribute("RarityColor") or Color3.fromRGB(200, 200, 200)
local selected = basket[pet.Name]
if deleteMode then
stroke.Color = selected and Color3.fromRGB(255, 0, 0) or Color3.fromRGB(180, 180, 180)
stroke.Thickness = selected and 5 or 2
else
stroke.Color = isEq and Color3.fromRGB(85, 255, 127) or rarityCol
stroke.Thickness = isEq and 4 or 2
end
end
pet.AttributeChanged:Connect(function(attr)
if attr == "IsEquipped" or attr == "RarityColor" then
refreshStyle()
updateLabels()
end
end)
btn.Activated:Connect(function()
if deleteMode then
if pet:GetAttribute("IsEquipped") then return end
if basket[pet.Name] then basket[pet.Name] = nil else basket[pet.Name] = true end
updateBasketText()
refreshStyle()
else
petAction:FireServer(pet.Name)
task.delay(0.2, updateUI)
end
end)
refreshStyle()
end
No, and i tried everything i could to fix it.
I’ve made a print system before that will tell when image id is assigned to button, and it was assigned properly, but still it wont show.
Maybe run it in Studio to where you should see it, then manually look in the Explorer.
Even copy it and see if there is an image there at all. If so, it could be a ZIndex thing.
This looks a bit sus too..
btn.Size = UDim2.new(0, bSize.X, 0, bSize.Y)
Question is what bSize actually is at runtime.
If bSize is a Vector2 with valid values like Vector2.new(80, 80), the size will be fine.
If bSize.X or bSize.Y are 0, the button will render with no visible area.
Doing a runtime check should confirm both.
Maybe if you made a template button you could use that and just change the image per pet instead of creating the button entirely in a script. I did that myself and I remember an issue with buttons not showing up like yours which is why I switched to using a template.
It’s often better to combine it with UIScale or AnchorPoint/Size constraints for global adjustments. UIGridLayout is good for arranging UI elements in a uniform grid and for automatically adjusting spacing, padding, and cell size across different screen sizes. And these interfaces have different screen sizes.