Attempt to index string with 'image'

I’m trying to make a local script for a shop GUI which creates an entry into the shop GUI for all of the gears held within a folder stored on the Replicated Storage.

Here's the script which carries out the function:
local shopFrame = script.Parent:WaitForChild("ShopFrame")

local trailsFolder = game.ReplicatedStorage:WaitForChild("Gears")
local ownedTrailsFolder = game.Players.LocalPlayer:WaitForChild("OwnedGears")

function updateShop()

	for i, child in pairs(shopFrame:GetChildren()) do

		if child:IsA("Frame") then child:Destroy() end
	end


	local shopTrails = trailsFolder:GetChildren()

	table.sort(shopTrails, function(a, b)
		return a.Price.Value < b.Price.Value or a.Price.Value == b.Price.Value and a.Name < b.Name
	end)


	for i, trail in pairs(shopTrails) do

		local item = script.Item:Clone()
		
		item.Frame.Buy.Image.Title.Text = trail.Price.Value
		if ownedTrailsFolder:FindFirstChild(trail.Name) then item.Frame.Buy.Image.Title.Text = "Equip" end
		
		item.Frame.Title.Text = trail.Name
		item.Frame.Image.Image = trail.TextureId -- *The line of code generating the error

		item.Parent = shopFrame

		item.Frame.Buy.MouseButton1Click:Connect(function()
			game.ReplicatedStorage.Customization.GearSelectedRE:FireServer(true, trail)
		end)
		
		item.Frame.Buy.Image.Title.MouseButton1Click:Connect(function()
			game.ReplicatedStorage.Customization.GearSelectedRE:FireServer(true, trail)
		end)
	end
end


updateShop()

ownedTrailsFolder.ChildAdded:Connect(function()
	updateShop()
end)
ownedTrailsFolder.ChildRemoved:Connect(function()
	updateShop()
end)

trailsFolder.ChildAdded:Connect(updateShop)
trailsFolder.ChildRemoved:Connect(updateShop)

I am trying to make it so that the script copies the textureid of the gears in the shop into an image in the shop panel however I get this error when doing so:
.

Players.Eh_Canadian0.PlayerGui.Default.Customization.Shop2.Shop3.Gears.GearsGuiHandler:29: attempt to index string with 'Image'

.
What can I do to make this script function?

Is Frame an image? If so then Frame.Image may be referencing the frame image url(which is a string) instead of the child of the Frame(which is an image) called Image. A simple fix is to use a function that specifically looks for children like FindFirstChild:

item.Frame:FindFirstChild("Image").Image = trail.TextureId

In general, it’s not a good practice to give children of instances names that might be mistaken with properties.

1 Like

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