Pet images doesn't show

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

1 Like

(ignore me I forgot its meant to be capital)
Probably isn’t the cause but try making the ‘i’ lowercase.

2 Likes

I think that it is the good solution. Check if the visible propriety is good or not

I checked properties multiple times, and no, ZIndex is supposed to be with capital i

Have you ever had the pet image show in this interface?

What does this Attribute look like?
If it is like 123456789 this may be it.

The way this is set up should be.
rbxassetid://123456789

Or you could rewrite the call to..

local function refreshImg()
	btn.Image = "rbxassetid://" .. (pet:GetAttribute("Image") or "")
end
refreshImg()

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.

edit: it has rbxassetid://

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.

Is this using:
Capture
at all?

why arent you just using uigridlayout :sob:

1 Like

I will try to make a template button and i’ll let you know, also no, it doesnt use uigridlayout

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.

A template works well with this also.

At least this was true for me. Good luck.

Ty i’ll try it and create a new topic if issue still on

1 Like

I did it using Viewport and it’s working perfectly now

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.