Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Mouse1ButtonDown is not a valid member of ImageLabel fix?

Asked by 5 years ago

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
0
It should be ImageButton mixgingengerina10 223 — 5y
0
Change the imagelabel to an imagebutton... Envoked -11 — 5y
0
Ah, the lovely moment of realisation you missed 1 detail and wasted 2 hours of your life.. Welcome to the group User#20989 0 — 5y
0
feelsbadman Envoked -11 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

There actually isn't much wrong with your code. Only that the 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)
Ad
Log in to vote
-2
Answered by
Envoked -11
5 years ago

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.

0
This should have been a comment. mixgingengerina10 223 — 5y
0
Unfortunately, I have already tried this on multiple occasions. The same error still pops up. HarmonicPower 14 — 5y
1
MouseButton1Down will work on an ImageButton, make sure it's 100% a button and there aren't any syntax errors Vulkarin 581 — 5y
0
^^^ Vulkarin is correct, you misspelled MouseButton1Down like "Mouse1ButtonDown" fighter169mobile 123 — 5y
Log in to vote
-2
Answered by 5 years ago

Put it in a imagebutton and do MouseButton1Click instead of down

Answer this question