Can't seem to load image

Hi there! I have encountered a weird problem. I have a table which list all the weapons i have in my game. For eg.

local toys = {
	["Teddy Bear"] = {
		["ID"] = 1;
		["ImageID"] = 2612713867;
		["Price"] = 0, 
		["AmountToGive"] = 10, 
		["Limited"] = false
	};

Then over on the client, I clone the template imagebutton and replace the imagebutton’s image to the imageid

On the client [not the exact script]

script.Parent:FindFirstChild[toy.Name].Image = "rbxassetid://"..module[toy.Name]["ImageID"]

Instead of loading in the image, it just gives an error saying that the image cant be loaded in?

Any ideas on how I can fix it?

3 Likes

The id in your code is a decal id. For the image to be able to load, you need an image id. You can get this by pasting the id into a decal object in studio or subtracting 1 until you get it. Correct id: https://www.roblox.com/library/2612713854/Images-TeddyBear. You can see that the “type” is image now, not decal.

11 Likes

It appears you’re using the asset’s direct asset ID to render it in Roblox.
While I don’t precisely know why this is the case. Whenever you do so, a lot of times you’re met with the ‘Request failed’ error. What I do to solve this is I put the ID into an unused or temporary ImageLabel somewhere. Before copying the asset URL and using that.

For example: I have a decal under the ID of: ‘2920496107’ I put it into a ImageLabel which switched the ID to ‘2920496099’. Which when I load by script, works! While loading the image using ‘2920496107’ via a script gave me the ‘Request failed’ error.

3 Likes

hmm didnt notice that the Id changes

[smh the 50 words thing is actually not a great thing]

ah i see now. Decals id are different to image id. Thanks for the info :smile:

Just heads up for @posatta. Yes, you seem to use the decal id, not asset id.

I would do like what he suggests, insert a decal into a part or GUI, then paste your decal id there. Allow for around a minute, sometimes it takes as long as that or shorter. Or to make sure you notice the change, then change the Image value to 0.

2 Likes

hmm will look into the image id and decal id. Thanks for the help! :smile:

If you want a quick solution to retrieve the AssetId, you can load the asset in via InsertService and grab the decal. This is for runtime purposes though and only works with assets you own.

local InsertService = game:GetService("InsertService")

local Asset = InsertService:LoadAsset(id)
local AssetId = Asset:GetChildren()[1].Texture

Don’t @ me for not checking the instance type or anything. It’s an example.

3 Likes