Setting ImageLabel.Image with rbxassetid gives error

  1. What do you want to achieve?: I want to make an inventory gui for my custom inventory system

  2. What is the issue? I have a dictionary with all the image decals’ “rbxassetid” I uploaded to my develop tab. But when I get the data from there and set the ImageLabel.Image of an Image label in the inventory to that rbxassetid://6706653266" for example, it just displays a blank screen. Also, ik im using the same assetid for my leaves as my stone, that is because the leaves were not getting accepted.

  3. What solutions have you tried so far? I’ve tried only changing the “rbxassetid” to different things but I can’t find anything else that fits

This was just for me to learn data stores better and I just wanted to add some random item images so it will tie it up nicely.

Here is the relevant code:


--When press item pickup key
UIS.InputEnded:Connect(function(input, processed)
	if input.KeyCode == Enum.KeyCode.H then
		if mouse.Target then -- If the target exists
			if mouse.Target:FindFirstChild("Pickable") then -- If the target is pickable
				if player:DistanceFromCharacter(mouse.Target.Position) < 30 then -- If the player is close enough to the target(30 studs)
					--Add it to inventory gui
					local itemUI = game.ReplicatedStorage.ItemTemplate:Clone()
					itemUI.Parent = invGUI.MainInvFrame.ItemsFrame

					itemUI.ItemName.Text = mouse.Target.Name -- Sets the items name
					itemUI.ItemImage.Image = imageDecals[mouse.Target.Name] -- Sets the items image. <<<<<<THIS IS THE PROBLEM

					game.ReplicatedStorage.PickupItem:FireServer(mouse.Target) -- Ignore

				end
			end
		end
	end
end)

Table that is in a modulecript btw:

local imageDecals = {
	Leaves = "rbxassetid://6706653266",
	Wood = "rbxassetid://6706652011",
	Stone = "rbxassetid://6706653266"
}

return imageDecals

Here is the error message with the decal(it’s not only this one it’s the same with all of them like my wood and leaves) :
Image https://assetdelivery.roblox.com/v1/asset?id=6706653266 failed to load. Error 403: Asset type does not match requested type

Here is what appears when it runs:
image

Kindly ensure that all if conditional gates are passing the control in. Ensure that they do not return false.

I am sure that it reaches the ImageLabel.Image because it is showing the error that the asset type is what was wrong.

i dont think is rbxassetid:// i think its something like a long link try adding the image id in the imagelabel and see what link it produces and just copy that and that would be the link for your script

1 Like

This is probably because you need the asset image id, not decal id. If you want to get the image id easily, you can use rbxthumb://

string.format("rbxthumb://type=Asset&id=%s&w=420&h=420", Id)

You can also paste the decal id into an image in studio and it will automatically format it to the correct image id for you.

13 Likes

It worked thank you so much!
But I just want to clarify a few things:

  1. So whenever I need to add an image to a UI do I need to use rbxthumb?
  2. That %s in the asset id is just what the string.format’s use is? To insert the id from outside the messy text? Or is there another reason to use string.Format. Tbh I’ve never messed with string formatting so I don’t get that type of stuff
    Thanks again

Yup! It simultaneously indicates where the value provided in the second parameter will be added into the original string, in addition to specifying what type of value should be added (which in this case, is a string).

Example:

local Id = 1234567890
local newString = string.format("rbxthumb://type=Asset&id=%s&w=420&h=420", Id)

print(newString) -- "rbxthumb://type=Asset&id=1234567890&w=420&h=420"

More information about string formatting can be found on this Developer Hub page.

1 Like