Having an issue with loading a image

Im trying to load a basic image w/ PreloadAsync

Using this basic code that was mentioned on the docs

local cProvider = game:GetService("ContentProvider")

cProvider:PreloadAsync(imagesToLoad, function(ID, Status)
	print("PreloadAsync() resolved asset ID:", ID)
	print("PreloadAsync() final AssetFetchStatus:", Status)
end)

I try to load IDS by w/ "http://www.roblox.com/asset/?id=" .. (ImageID)
and for basically each id (besides 2) it shows:

  21:23:59.588  PreloadAsync() resolved asset ID: http://www.roblox.com/asset/?id=11139517382 - Client - LocalScript:17
  21:23:59.588  PreloadAsync() final AssetFetchStatus: Enum.AssetFetchStatus.Failure

yet when i just apply the imageID to a imagelabel in studio it appears
image

anyone know why this is happening and how i could posssibly fix it?

^ Image used

Try changing it to be rbxassetid://

1 Like

You need to provide the image ID instead of the decal ID. They’re separate assets and PreloadAsync expects the former. You can convert a decal ID to its image ID with a couple methods in Studio:

  • Insert the decal ID into a Decal Instance and get the new ID it produces
  • Use a plugin like Imiji that simplifies the next method
  • Use LoadAsset or GetObjects to load the Decal and read its Texture property
2 Likes

This i did not know, thanks for the info :+1:

Using your method mentioned here:

I created a server script with the code:

local marketPlaceService = game:GetService("MarketplaceService")
local insertService = game:GetService("InsertService")
local clientLoadFolder = game.ReplicatedStorage.ClientLoad
local gUI_Images = require(game.ReplicatedStorage.GambleUI_HeldAssets.Modules.itemFrameManager.ImageIds)

local ids = {}

for imageName, imageTable in pairs(gUI_Images) do
	if imageTable["ItemID"] then
		ids[imageName] = imageTable["ItemID"]
	end
end

local baseDecal = Instance.new("Decal")

local function loadID(id, name) 
	local aI = marketPlaceService:GetProductInfo(id, Enum.InfoType.Asset)
	
	if aI.AssetTypeId ~= Enum.AssetType.Decal.Value then
		warn("Error loading id: " .. id)
		return
	end

	local newDecal = insertService:LoadAsset(id):FindFirstChildWhichIsA("Decal")
	newDecal.Parent = clientLoadFolder
	
	newDecal.Name = name
end

for name, id in pairs(ids) do
	loadID(id, name)
end

and on the client i used:

local clientLoad = game.ReplicatedStorage.ClientLoad
local cProvider = game:GetService("ContentProvider")

-- eventaully add a check when all images are loaded
task.wait(2)
local idTable = {}
for _, decal : Decal in ipairs(clientLoad:GetChildren()) do
	local trueId = string.split(decal.Texture, "http://www.roblox.com/asset/?id=")[2]
	
	itemFrameManagerModule.OverwriteImage(decal.Name, trueId)
	table.insert(idTable, "rbxassetid://" .. trueId)
	
	decal:Destroy()
end

cProvider:PreloadAsync(idTable, function(ID, Status)
	print("PreloadAsync() resolved asset ID:", ID)
	print("PreloadAsync() final AssetFetchStatus:", Status, "\n")
end)

used the rbxassetid:// mentioned here:


and it was able to work perfectly!

Thank you both for your help :heart:

1 Like

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