So basically I am making a game which relies heavily on image labels I am using a script to set the image DYNAMICALLY I do not set the asset id’s before hand.
The issue is that my image is not loaded or image label is blank even though I set the asset id through the script.
I have tried looking thorough the dev forum for solutions but there was not really anything on this topic.
After that, you should include more details if you have any.
Here is my script could anyone help fix my issue thanks!
local HttpService = game:GetService(“HttpService”)
local RS = game:GetService(“ReplicatedStorage”)
local Events = RS:WaitForChild(“Events”)
local MetadataEvent = Events:WaitForChild(“MetadataEvent”)
local Players = game:GetService(“Players”)
– Function to handle JSON parsing
local function parseJson(jsonString)
local success, result = pcall(function()
return HttpService:JSONDecode(jsonString)
end)
if success then
return result
else
warn("Error parsing JSON:", result)
return nil
end
end
– Function to handle cloning and decal placement based on metadata
local function handleMetadata(metadata)
local MainGui = Players.LocalPlayer:WaitForChild(“PlayerGui”):WaitForChild(“MainGui”)
local Template = RS:WaitForChild(“Template”)
local Frame = MainGui:WaitForChild(“Frame”)
for assetId, assetMetadata in pairs(metadata) do
print("ASSET_ID: " .. assetId)
-- Clone the UI template from MainGui for each metadata
local TemplateClone = Template:Clone()
TemplateClone.Parent = Frame
TemplateClone.Name = "TemplateClone" .. assetId
-- Update the cloned template with asset information
local ImgLabel = TemplateClone.ImageLabel
ImgLabel.Image = string.format("rbxthumb://type=Asset&id=%s&w=150&h=150", tostring(assetId))
TemplateClone.Visible = true
-- Display metadata in Output
print("Metadata for assetId " .. assetId .. ":")
for category, data in pairs(assetMetadata) do
print(category, "Name:", data.Name, "Rarity:", data.Rarity)
end
end
end
MetadataEvent.OnClientEvent:Connect(function(metadata)
if metadata then
print(“Received Metadata:”, metadata)
-- Example: Handle metadata on the client side
handleMetadata(metadata)
else
warn("Received empty metadata.")
end
end)