Set image property by script

  1. What do you want to achieve?

working on an inventory system
I want an image of the item in the background. and the image needs to change every time the item in that slot changed

  1. What is the issue?

the image will not show
afbeelding
the output says :" Image “https://assetdelivery.roblox.com/v1/asset?id=2612713853” failed to load in “Players.LocalPlayer.PlayerGui.CoreGui.RightDisplay.Backpack.Container.Container.Bac1.Icon.Image”: Request failed](rbxopenprop://0%2e3086718/Image)"

  1. What solutions have you tried so far?
  • Image failed to load – mentioned copying from the image id
  • Can't seem to load image – mentioned that the image id might be wrong so used “2612713854” and “2612713855”
  • Images not loading [SOLVED] – mentioned subtracting 1 so tried from 1 to 10 (manually)
  • having the image already loaded in a different image button
  • game:GetServiceContentProvider’:PreloadAsync(…) (same error but faster)
  • rbxassetid://
  • http://www.roblox.com/asset/?id=
  • let the script change the image, hit enter on the property after it changed

The script does adjust the image property in the image

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

the script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ItemDictionary = require(ReplicatedStorage.Core.Dictionarys.ItemDictionary)
function onItemChange()
	local Item = script.Parent.ItemName.Text
	local newimage = "rbxassetid://"..tostring(tonumber(ItemDictionary[Item]["ImageId"])-1)
	--print (newimage)
	script.Parent.Icon.Image = newimage
end
script.Parent.ItemName:GetPropertyChangedSignal("Text"):Connect(onItemChange)
the dictionary
local ItemDictionary = {
   ["Sword"] = {
   	["Description"] = "a training sword",
   	["BackpackStackSize"] = 1,
   	["BankStackSize"] = 1,
   	["Value"] = 0,
   	["ModelId"] = 0,
   	["ImageId"] = 2612713854,
   },
}

any suggestions are welcomr

You can’t just use the “-1” trick on IDs— most of the time, the image ID will be multiple digits below the asset ID. Instead, go manually set all of the image IDs in your table to be the actual image ID (you can find them easily by just inserting the assetID into something like an ImageLabel— the ID will automatically be converted to image, and you can then go copy it)

1 Like

You have to put the id into a decal and use the new ID given; It’s a weird roblox bug.

1 Like

I had this same problem and it was resolved by simply publishing my game. Have you published your game?

1 Like

I have published the game,
no change

I’m stumped. I see no problems in your code. Have you tried @Rezault’s solution?

2 Likes

I’ve had the same issue before and my solution worked.

sorry for the late reply.

at first, it didn’t solve it.
but turns out it was an issue on my side where I still did the number -9 (old code trying to fi the issue)

rechecked everything, and yeah sometimes they do really weird stuff with the numbers?

afbeelding
(image is not mine and just there as an example)