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
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.