I've been trying to make this image label clickable for the past two hours. No matter what I did it would come up with the error "Mouse1ButtonDown is not a valid member of ImageLabel"
function Transfer() for i, v in pairs(StoredItems) do local Label = Instance.new("ImageLabel"); Label.Parent = Handler; Handler:WaitForChild("ImageLabel") Label.Name = v.Name Label.Image = v.TextureId Label.MouseButton1Down:connect(function() if Handler.Selected.Value == nil or Handler.Selected.Value ~= v then script.Parent.ItemName.Text = v.name end end) end end
ImageButton
class has that MouseButton1Down
event you were looking for. MouseButton1Down
runs code whilst the mouse is pressed down on the GuiButton
, which can repeat code. You may want to use MouseButton1Click
unless the former is what you want. If a GuiObject
has the word "Button" in its ClassName
, you know it is a button, which can obviously be clicked. I also fixed your code up a bit, you're welcome.local Button local function Transfer() for i, v in pairs(StoredItems) do value = v Button = Instance.new("ImageButton") Button.Name = v.Name Button.Image = v.TextureId Button.Parent = Handler -- always assign the parent last end end Button.MouseButton1Click:Connect(function() -- :connect is deprecated, use :Connect if not Handler.Selected.Value or not StoredItems[Handler.Selected.Value] then script.Parent.ItemName.Text = value.Name end end)
I think you have ImageLabel confused with ImageButton. ImageLabel is a regular image, while ImageButton is a clickable image. All you have to do is swap them out.
Put it in a imagebutton and do MouseButton1Click instead of down