Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Image failure to load in after using a variable to change images?

So i'm trying to make an in-game power-point system where the user clicks a part, and enters the ID of a decal and the decal will show up on the image label/ surface GUI.

heres the script so far

script.Parent.FocusLost:Connect( --in a text box so the player can enter the decal ID
	function(enterPressed)
		if enterPressed then
			script.Parent.Value.Value = script.Parent.Text
			script.Parent.Parent.Visible = false
			script.Parent.Text = "Text Here..." --ignore everything above this
			local part = game.Workspace.ShowPart
			local value = script.Parent.Value.Value
			part.SurfaceGui.ImageLabel.Image = ("http://www.roblox.com/asset/?id="..value)
		end
	end
)`

error message:

"Image "https://assetdelivery.roblox.com/v1/asset?id(image i want)" failed to load in "Workspace.ShowPart.SurfaceGui.ImageLabel.Image": Request failed

I tried using the rbxasset:// thingy, everything else system wise is working. sorry for sloppy, first post new to this website

i am not looking for criticism with my code, I've been scripting for a few months and im pretty proud of how far i've come

5 comments

0

by criticism i mean like people saying to indent, and how i've written some parts of the code, suggestions are fine thanks if you reply!

0

:connect is deprecated, use :Connect

0

thanks

0

try using "rbxassetid://" rather then "http://www.roblox.com/asset/?id=" or "rbxasset://"

0

as stated, i have

1 answer

I'm not sure if this will work but I did my best! Here you go. This should function as you intend it to.

local Workspace = game:GetService("Workspace")
local TextBox = (script.Parent:IsA("TextBox") and script.Parent) or script:FindFirstAncestorOfClass("TextBox")
TextBox.PlaceholderText = ("Text here!");
TextBox.FocusLost:Connect(function(EnterPressedEvent)
	if not EnterPressedEvent then
		return
	end
	local ShowPart = Workspace:FindFirstChild("ShowPart")
	local Value = TextBox.Value.Value
	pcall(function()
		local SurfaceGui = ShowPart:FindFirstChildOfClass("SurfaceGui")
		SurfaceGui:FindFirstChildOfClass("ImageLabel").Image = ("rbxassetid://") .. string.match(TextBox.Text,("%d+")); -- "%d+" is a pattern type which gets the digits in the string.
	end)
end)

1 comment

0

Sometimes referring to a decal on the library will not work, but when you attempt to load in the decal on studio it comes up as an Image asset, so maybe you're not using the right asset type for your textbox either?

This discussion is preserved as it was. New answers, comments, and votes are closed.