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
You could try doing :WaitForChild(), the object might not of loaded yet, so use that to wait for it to appear
17:39:58.869 - Infinite yield possible on 'Sword:WaitForChild("PreviewThumb")'
I tried it, but got this error. Thank you for the answer anyways! It seemed like it could work, since I have slow internet.