MouseButton2 not working with GUI text buttons

Hi, title explains it all. I can’t seem to get mousebutton2 working with my gui text buttons.

KqvOt8Jn03

This is my current code.

local test = MainFrame.UIGridLayout:GetChildren()
	for i,v in pairs(test) do
		print(test,i,v)
		v.MouseButton2Down:Connect(function()
			print('y arent u clicking')
		end)
	end

MainFrame is set to

local MainFrame = game.Players.LocalPlayer.PlayerGui.Backpack.BackpackUI.Frame

I’m not sure where im going wrong because this is pretty self explanatory, I believe my code is setup correctly as well.

The buttons don’t seem to be a child of UIGridLayout, that’s probably why.

Look at your video.

I cant get the children of just the frame because you cant use mousebutton2down on a uigridlayout.

Use an if statement paired with :IsA().

for i, v in ipairs(MainFrame:GetChildren()) do
	if v:IsA("GuiObject") then
		-- Code
	end
end
2 Likes