How to get what button a player clicked on

How check which button a player clicked on? through an I, v in pairs loop?

3 Likes

Sure but I would just use the following for simple projects.

script.Parent.MouseButton1Click:Connect(function()

end)

Or you could use

if Instance:IsA("TextButton") then
     if Instance.Name == "OpenFrameButton" then
          --code here
     end
end
1 Like

How would I do that on here?

local Order1 = false
local Order2 = false
local Order3 = false

for i, vp in ipairs(script.Parent.ImageLabel:GetChildren()) do
	if vp:IsA("Frame") then
		for t,im in pairs(vp:GetChildren()) do
			if im:IsA("ImageLabel") then
				im.MouseButton1Click:Connect(function()
					if Order1 ~= false then
						print("Order slot filled!")
					else
						Order1 = true
						script.Parent.Item1.Value = im:FindFirstChild("TextLabel").Text
						print(im:FindFirstChild("TextLabel").Text)
					end
				end)
			end		
		end
	end
end

Can you send a picture of the explorer window, specially the whole ScreenGui.

local Order1 = false
local Order2 = false
local Order3 = false

for i,v in ipairs(script.Parent.ImageLabel:GetChildren()) do
	if v:IsA("Frame") then
		for t,a in pairs(v:GetChildren()) do
			if a:IsA("ImageLabel") then
				a.MouseButton1Click:Connect(function()
					print(a.Name.." was clicked.") -- see if it prints the buttons name, if so replace this line of code with the orginal piece
				end)
			end		
		end
	end
end

Edit: Wait, are their ImageButtons inside of the Frames? If so it should be if a:IsA("ImageButton") then NOT if a:IsA("ImageLabel") then.

It’s not printing. Do you know why?

1 Like

Are there any errors in the output or does it simply not work?

it just doesn’t work. not sure why

Upon further analysis, I noticed that you’re checking for an ImageLabel, which does not have a MouseButton1Click event ( you should have recieved an error for this in the output ). Did you mean to use an ImageButton instead?

ImageLabel Doesnt support MouseButton1Click.
Try InputBegan Instead.

ImageLabel.InputBegan:Connect(function(object)
   if object.UserInputType == Enum.UserInputType.MouseButton1 then
     -- Code here
   end
end)
Heres the code
local Order1 = false
local Order2 = false
local Order3 = false

for i, vp in ipairs(script.Parent.ImageLabel:GetChildren()) do
	if vp:IsA("Frame") then
		for t,im in pairs(vp:GetChildren()) do
			if im:IsA("ImageLabel") then
				im.InputBegan:Connect(function(input)
					if input.UserInputType == Enum.UserInputType.MouseButton1 then
						if Order1 then
							print("Order slot filled!")
						else
							Order1 = true
							script.Parent.Item1.Value = im:FindFirstChild("TextLabel").Text
							print(im:FindFirstChild("TextLabel").Text)
						end
					end
				end)
			end		
		end
	end
end