Problem reading Image from Hotbar script

Hello, recently I started making Inventory Gui with Hotbar, but the problem is that I have the following script, but ItemImage, which is an ImageLabel, which does not react at all to the change of Image, does not change even if in explorer there is a photo in the propporties, then on it doesn’t show up in the user interface.For now only hotbar, ignore Inventory part script. There are generally two slots and I need to correct this or propose a new solution. Below I am sending a picture and code that I hope will help to solve the problem.

game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local player = game.Players.LocalPlayer
local char = workspace:WaitForChild(player.Name)
local bp = player.Backpack
local OnScreen = game.StarterGui.Onscreen
local InventoryGui = game.StarterGui.Inventory.Main.Holder
local hotbarSlots = {OnScreen.SlotOne, OnScreen.SlotTwo}
local hotbarImages = {OnScreen.SlotOne.ItemImage, OnScreen.SlotTwo.ItemImage}
local inventorySlots = {}
for i = 1, 20 do
	table.insert(inventorySlots, InventoryGui:FindFirstChild(tostring(i)))
end

local function updateSlot(slot, image, tool)
	if tool then
		slot.Text = tool.Name
		image.Image = tool.TextureId
	else
		slot.Text = ""
		image.Image = ""
	end
end

local function toolAdded(tool)
	for i, slot in ipairs(hotbarSlots) do
		if slot.Text == "" then
			updateSlot(slot, hotbarImages[i], tool)
			return
		end
	end

	for i, slot in ipairs(inventorySlots) do
		if slot.Text == "" then
			updateSlot(slot, nil, tool)
			return
		end
	end
end

bp.ChildAdded:Connect(function(child)
	if child:IsA("Tool") then
		toolAdded(child)
	end
end)

char.ChildAdded:Connect(function(child)
	if child:IsA("Tool") then
		toolAdded(child)
	end
end)

1 Like

texture ids, and image ids are different (link wise)

image ids are rbxassetid://(id)
texture ids are http://www.roblox.com/asset/?id=(id)

what a fix could be is

local imageid = string.match(tool.TextureId,"%d+") --geting the texture id to convert into a image id
image.Image = "rbxassetid://"..imageid --using the numbers and a string to convert

“%d+” finds all numbers in string.match :slight_smile:


(just a test on my own script, that isn’t that different)