Why doesn't this part of my code work?

Hey, so I’m trying to make a menu for my game and I’m confused why this doesn’t work:

for i, v: ImageButton in pairs(Tabs:GetChildren()) do
	if v:IsA("ImageButton") then
		v.MouseButton1Down:Connect(function()
			print("hi")
		end)
	end
end

Nothing shows up in the output at all and I don’t want to connect every button to a function manually.

Can somebody explain why this isn’t working?

(it prints until the connect function part)

i tried your script and it does works for me
maybe the button doesn’t detect that you are clicking them or something like that

2 Likes

check the children of the tabs instance at runtime, do:
for _,v in ipairs(tabs.GetChildren(tabs)) do print(v) end
right before your other iteration statement

1 Like

I forgot that my button’s transparency value was 1 and I think that was the problem, thanks for reminding me of that.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.