Does anyone know why the image won't load being set in the script?

Title says it all. When I input a value, it gets set in the image’s value, but it doesn’t load (checked under the properties tab where it says IsLoaded)

Script:

local sound = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Clans"):WaitForChild("Click")
local box = script.Parent.Parent.TextBox
local limit = script.Parent.Parent.Limit
local preview = script.Parent.Parent.Parent.ImagePreview
local lightRed = Color3.fromRGB(255, 64, 67)
local placeholderImageID = "rbxassetid://6673968185"

local value = script.Parent.Parent.Parent.Submit.ClanImage

script.Parent.MouseButton1Click:Connect(function()
	sound:Play()

	local textLength = string.len(box.Text)
	local spaceCount = select(2, box.Text:gsub(" ", ""))

	if textLength < 3 or textLength > 20 or spaceCount > 0 then
		limit.TextColor3 = lightRed
		box.UIStroke.Color = lightRed
		value.Value = 6673968185
		preview.Image = placeholderImageID
	else
		local success, result = pcall(function()
			local productInfo = game:GetService("MarketplaceService"):GetProductInfo(box.Text)
			if productInfo.AssetTypeId == 13 then
				return "rbxassetid://" .. box.Text
			else
				return false
			end
		end)

		if not success or not result then
			limit.TextColor3 = lightRed
			box.UIStroke.Color = lightRed
			value.Value = 6673968185
			preview.Image = placeholderImageID
		else
			limit.TextColor3 = Color3.new(1, 1, 1)
			box.UIStroke.Color = Color3.fromRGB(68, 68, 68)
			value.Value = box.Text
			preview.Image = result
		end
	end
end)

Thanks

right off the bat

i don’t know why, and i can’t explain why, but for whatever god damn reason you cannot set images via script unless you use a complicated format (which only supports resolutions from 150x150 to 420x420)

you can use the complicated format:

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

but otherwise, unless someone else helps you, you’re gonna have to have image PRESETS stored somewhere (like ReplicatedStorage), then clone those image labels and alter them however you’d like

2 Likes

I can’t have them preset stored, because they are user-inputted. But I will try your first method.

then i don’t know how else to help you besides that string.format thing

Yeah I did that and it worked. Leaving this fixed script here for anyone who needs it:

local sound = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Clans"):WaitForChild("Click")
local box = script.Parent.Parent.TextBox
local limit = script.Parent.Parent.Limit
local preview = script.Parent.Parent.Parent.ImagePreview
local lightRed = Color3.fromRGB(255, 64, 67)
local placeholderImageID = "rbxthumb://type=Asset&id=%s&w=420&h=4206673968185"

local value = script.Parent.Parent.Parent.Submit.ClanImage

script.Parent.MouseButton1Click:Connect(function()
	sound:Play()

	local textLength = string.len(box.Text)
	local spaceCount = select(2, box.Text:gsub(" ", ""))

	if textLength < 3 or textLength > 20 or spaceCount > 0 then
		limit.TextColor3 = lightRed
		box.UIStroke.Color = lightRed
		value.Value = 6673968185
		preview.Image = placeholderImageID
	else
		local success, result = pcall(function()
			local productInfo = game:GetService("MarketplaceService"):GetProductInfo(box.Text)
			if productInfo.AssetTypeId == 13 then
				return string.format("rbxthumb://type=Asset&id=%s&w=420&h=420", box.Text)
			else
				return false
			end
		end)

		if not success or not result then
			limit.TextColor3 = lightRed
			box.UIStroke.Color = lightRed
			value.Value = 6673968185
			preview.Image = placeholderImageID
		else
			limit.TextColor3 = Color3.new(1, 1, 1)
			box.UIStroke.Color = Color3.fromRGB(68, 68, 68)
			value.Value = box.Text
			preview.Image = result
		end
	end
end)

AI summarised this:

  • Replaced local placeholderImageID = “rbxassetid://6673968185” with local placeholderImageID = “rbxthumb://type=Asset&id=6673968185&w=420&h=420”

  • Replaced return “rbxassetid://” … box.Text with return string.format(“rbxthumb://type=Asset&id=%s&w=420&h=420”, box.Text).

SOMETHING WORTH NOTING (leaving this incase some fool tries this and fails miserably)

the string.format method ONLY WORKS for resolutions from 150x150 up to 420x420, anything lower OR higher will ERROR

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