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

"PreviewThumb is not a valid member of Tool"... But I can see it in explorer?

So, I have an inventory set up with a couple of test items. There are options to drop, equip, and display lore. All work fine, except for one. When I drop an item, clicking on the item no longer triggers anything because for some reason, it thinks there is no imagelabel in the tool.

The function works by getting a list of tools in a folder and making a new imagebutton for each of the tools. I have in each tool an ImageLabel named "PreviewThumb". When I activate the drop, it seems to no longer think that I have one there, when I can clearly see it in studio. I even made a thing that did a FindFirstChild("PreviewThumb") and only ran the code if FIndFirstChild == true. It was equal to true, yet in the very next line of code, it had an error saying there was no previewThumb! Infuriating! Here are my variables.

local InvGUI = script.Parent.InvMenu.Main
local InvList = InvGUI.List
local BackPack = script.Parent.Backpack
local getItems = BackPack:GetChildren()
local TableIns = table.insert
local TableRem = table.remove
local loot = game.ServerStorage.Loot
local character = script.Parent.Parent.Character
local Player = script.Parent.Parent
local CarryWeight = InvGUI.Parent.CarryWeight
local CarryWeightDisplay = InvGUI.Info.CarryWeight
local GuiStorage = game.ServerStorage.GuiStore
local ItemsTable = {}
local Listing = false
local DestroyThese = {}

I am very sorry for the messy code. For clarification, MakeList() fires on the player pressing E, along with a separate function that enables the GUI. The line at which the script stops and gives the "PreviewThumb is not a valid member of Tool" error is 19 below. Any help at all would be greatly appreciated.

function MakeList(label)
print("Makelist Fired!")

for i = 1,#getItems do
	
	print(getItems[i]:GetFullName())
	print("Forloop fired", i, "times!")

	print("Create button fired!")
	
	
	CarryWeightDisplay.Text = CarryWeight.Value
	
local button = Instance.new("ImageButton")
local listcon = Instance.new("UIListLayout")
button.Parent = InvList

		
		button.Image = getItems[i].PreviewThumb.Image
        button.Name = getItems[i].Name
        listcon.Parent = button
        button.MouseButton1Down:connect(function(label)
		
		if Listing == false then
			
		Listing = true
		
		local Equip = GuiStorage.ItemTemplate:Clone()
		Equip.Name = "Equip"
	Equip.Parent = button
	Equip.Text = "Equip"
	
	Equip.MouseButton1Click:connect(function(Clicked)

	local BClone = BackPack[button.Name]:Clone()	
	character.Humanoid:EquipTool(BClone)
	
	local PlayerPack = Player.Backpack:GetChildren()
	
	for i = 1,#PlayerPack do
		if PlayerPack[i].ClassName == "Tool" then
			PlayerPack[i]:Destroy()
		end
end
	
	end)
	

	local Drop = GuiStorage.ItemTemplate:Clone()
	
	Drop.Name = "Drop"
	Drop.Parent = button
	Drop.Text = "Drop"
	Drop.MouseButton1Click:connect(function(DropClicked)
		
		CarryWeight.Value = CarryWeight.Value - BackPack     [button.Name].ItemWeight.Value 
		local BCDrop = loot[button.Name]
		local CloneDrop = BCDrop:Clone()
		TableIns(DestroyThese, button.Name)
		CloneDrop.Parent = workspace
		CloneDrop:MoveTo(character.HumanoidRootPart.Position)
		button:Destroy()
	end)
	
	local Lore = GuiStorage.ItemTemplate:Clone()
	Lore.Name = "Lore"
	Lore.Parent = button
	Lore.Text = "Lore"
	
	Lore.MouseButton1Click:connect(function(LoreClicked)
		
		InvGUI.Info.LoreBox.Text = BackPack[button.Name].Lore.Value
		
	  				 end)
				end
			end)

	button.MouseLeave:connect(function(label)
		
		
		
		local GetList = button:GetChildren()
		
		for i = 1,#GetList do
			
			if GetList[i].ClassName == "TextButton" then
				
				GetList[i]:Destroy()
				
				Listing = false
				
			end
			
			
		end
		
		
	end)


		end
	end

3 comments

0

You could try doing :WaitForChild(), the object might not of loaded yet, so use that to wait for it to appear

0

17:39:58.869 - Infinite yield possible on 'Sword:WaitForChild("PreviewThumb")'

0

I tried it, but got this error. Thank you for the answer anyways! It seemed like it could work, since I have slow internet.

1 answer

Okay, I might have to make some edits to this answer, but I think I know why you're getting the error.

On line 19, I notice you're trying to pick one item from the "BackPack". In each item, is there another item in it called "PreviewThumb"? If there isn't or at least one item doesn't have it, then you'll get that error.

Try adding the "PreviewThumb" to every item in the "BackPack" and it should work.

6 comments

0

That's the thing, there is a "PreviewThumb" in every item of backpack. I probably should have mentioned that. Thank you for the answer, though.

0

Try checking if any of the PreviewThumbs have a typo or not, and make sure NOTHING in the BackPack is missing one. If that doesn't work, then I don't know. :I

0

Oh, and make sure the PreviewThumbs are parented to the item in the backpack, not parented inside something that's inside the item.

0

I checked all that both in studio, and playing solo, and it all checks out. :/

0

I don't know what else to do. Sorry.

0

It's alright, not your fault at all. Thank you for trying to help.

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