It's not working

for _, But in pairs(script.Parent.Frames.Frame:GetChildren())do

	
	if But:IsA("TextButton")then
		But.MouseButton1Click:Connect(function()
		print("Inside FINALLYYYYYYYYY")
		end)
		end
end

I basically just want it to work when i click the button inside any frame
image

You have to either iterate through the descendants of the frame or create a second loop inside of the first loop.

for _, frame in pairs(script.Parent.Frames:GetChildren()) do
	if frame:IsA("Frame") then
        for _,button in pairs(frame:GetChildren()) do
			button.MouseButton1Click:Connect(function()
				print("Inside FINALLYYYYYYYYY")
			end)
		end
    end
end

or

for _, button in pairs(script.Parent.Frames:GetDescendants()) do
	if button:IsA("GuiButton") then
		button.MouseButton1Click:Connect(function()
			print("Inside FINALLYYYYYYYYY")
		end)
	end
end
1 Like

That only works when i click 1 frame

Oh the second one worked tysm <3

1 Like

Hey sorry for this but how can i check which frame did the player click like frame 1 or 2 or what

You can probably give it an attribute called “FunctionType” and then create a table whose index is the FunctionType and the value is the function.

local functionTypes = {
    ['PrintHi'] = function()
        print('Hi')
    end;
    ['PrintBye'] = function()
        print('Bye')
    end;
}
-- ...
button.MouseButton1Click:Connect(functionTypes[button:GetAttribute('FunctionType')])
1 Like

No i mean like to if da player like clicked 2nd or 3rd frame and print it
for example if a player clicked the 3rd frame i want it to print(“player clicked 3rd frame”)

Then you could do

button.MouseButton1Click:Connect(function()
    print(button)
end)
1 Like

if a player clicks the 6th button the text in the viewport become “6” instead of “1” same for every other buttons thats what i was trying to do