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

Mouse1ButtonDown is not a valid member of ImageLabel fix?

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

4 comments

0

It should be ImageButton

0

Change the imagelabel to an imagebutton...

0

Ah, the lovely moment of realisation you missed 1 detail and wasted 2 hours of your life.. Welcome to the group

0

feelsbadman

3 answers

✓ Accepted answer

###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)

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.

4 comments

0

This should have been a comment.

0

Unfortunately, I have already tried this on multiple occasions. The same error still pops up.

1

MouseButton1Down will work on an ImageButton, make sure it's 100% a button and there aren't any syntax errors

0

^^^ Vulkarin is correct, you misspelled MouseButton1Down like "Mouse1ButtonDown"

Put it in a imagebutton and do MouseButton1Click instead of down

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