How to show a Tool’s icon/texture in a GUI ImageLabel?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I just want to figure out how to make the texture from a tool appear in an image.
In my current code, the image always shows as nil. But what I actually want is: when a player gives me an item, the image (or icon/texture) of that item should appear.
I’ve tried several other approaches but failed. Is there any solution to fix this?
Any help would be greatly appreciated. Thank you!

Code

RemoteEvent.OnClientEvent:Connect(function(fromPlayer, toolName)
	frame.Visible = true
	nameLabel.Text = fromPlayer.Name .. " Give" .. toolName

	local character = player.Character
	local tool = character:FindFirstChildOfClass("Tool")
	if toolName and toolName.TextureId then
		fotoItem.Image = toolName.TextureId
	else
		fotoItem.Image = "rbxassetid://0"
	end

	local thumbnail, ready = Players:GetUserThumbnailAsync(
		fromPlayer.UserId,
		Enum.ThumbnailType.HeadShot,
		Enum.ThumbnailSize.Size100x100
	)
	if ready then
		fotoKtp.Image = thumbnail
	end
	
	yesBtn.MouseButton1Click:Connect(function()
		MengonfirmasiGiveBangKu:FireServer(fromPlayer, toolName, true)
		task.wait(0.5)
		frame.Visible = false
	end)


	noBtn.MouseButton1Click:Connect(function()
		MengonfirmasiGiveBangKu:FireServer(fromPlayer, toolName, false)
		frame.Visible = false
	end)
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

could you share if the image is being set to rbxassetid://0 or nothing? because if its being set to rbxassetid://0 that means your tool just doesnt have a texture, and if its being set to nothing then something went wrong when assigning .image

1 Like

@athony2025 Your previous comment (before you edited your messsage) was right.

You are trying to index a property called TextureId from the toolName, which, I assume, is a string name of the tool’s name, which is not exactly right. You want to get the received Tool instance to index the TextureId property.

https://create.roblox.com/docs/reference/engine/classes/Tool#TextureId

2 Likes

whoops, sorry about that, i thought toolname was the actual tool instance rather than its name

Oh, I see! That makes sense — I was using toolName as a string instead of the actual Tool instance.
So I should first get the Tool object (the one the player gives me), and then use .TextureId from that Tool, right?
Thanks for clarifying!

-- instead of this:
fotoItem.Image = toolName.TextureId  

-- do this:
fotoItem.Image = tool.TextureId  -- where "tool" is the actual Tool instance

Yes. Please refer to the link I have attached in my previous reprly.

1 Like

You could use the tool’s TextureID for the Hotbar as the texture for the GUI ImageLabel.

local player = game:GetService("Players").LocalPlayer
local tool = player:WaitForChild("Backpack")
	:WaitForChild("Pizza")

local textueId = tool.TextureId
local imageLabel = script.Parent --test script in the ImageLabel
imageLabel.Image = textueId --tool.TextureId to the ImageLabel.Image

If you’re using a transparent background on the tools.TextureId.. even better. (maybe) :smirking_face:

You could also put the tool or model inside a ViewportFrame..
Set up a Camera and the ViewportFrame will render it directly to the GUI ImageLabel.
This is pretty sweet, as you can get nice angles on the 3D object for the ImageLabel.

Testing..
Simple GUI, Path: StarterGui.ScreenGui.Frame.ImageLabel
Using the tool: Pizza Tool, ID 14002773553
LocalScript in the ImageLabel..

local player = game:GetService("Players").LocalPlayer
local tool = player:WaitForChild("Backpack"):WaitForChild("Pizza")
local frame = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Frame")
local imageLabel = frame:WaitForChild("ImageLabel")

local viewport = Instance.new("ViewportFrame")
viewport.Size = UDim2.new(1,0,1,0)
viewport.Position = UDim2.new(0,0,0,0)
--viewport.BackgroundTransparency = 1
viewport.Parent = imageLabel

local camera = Instance.new("Camera") camera.FieldOfView = 25
camera.CFrame = CFrame.new(Vector3.new(2,2,2), Vector3.new(0,0,0))
viewport.CurrentCamera = camera

local cloneTool = tool:Clone() cloneTool.Parent = viewport
cloneTool.Handle.CFrame = CFrame.new(0,0,0) * CFrame.Angles(math.rad(-15), math.rad(35), 0)

After 33 guesses on the Angles that is.. :roll_eyes:

2 Likes

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