How can I make buttons that switch between the visible and invisible uis

If I press the button the frame that is already visible will become invisible and the other frame will become visible. How can I achieve that?

5 Likes

Something like this may work

local Frame1 = ...
local Frame2 = ... -- Set these 3 things
local Button = ...

local State = false

Button.Activated:Connect(function()
    State = not State
    Frame1.Visible = State
    Frame2.Visible = not State
end)
2 Likes

What if I made more?
Could you help me make it like a loop?

2 Likes

Is it meant to cycle through the frames with each press, or is there 2 ā€˜groupsā€™ of frames, which it will alternate between

1 Like

I meant all the frames inside a folder. So for example i have 50 frames there and i press one. I want it to check if any of the frames are visible and make them invisible. Then make the other frame visible.

1 Like

What would the ā€œother frameā€ be though?

1 Like

The button that would make the frame vidible for example button 1 would open a frame while closing the other frames

are you possibly referring to this example Iā€™ll give:

For example:

local button1 = -- Button1
local button2 = -- Button2

local Frame1 = -- Frame Here
local Frame2 = -- Frame2 Here

Where in if button1 is pressed, Frame1 will be revealed, and if button2 was pressed, Frame2 will be revealed.

And whenever Frame2 is still open and you Pressed button1, it will Hide Frame2 and Reveal Frame1, vice versa. Is that it?

1 Like

Yes like that thats what i want

its simple, you can get @SeargentAUS 's example, and youā€™d just have to duplicate the

Button1.Activated:Connect(function()
-- code here
end)

Button2.Activated:Connect(function()
-- code here
end)

And you would place the necessary coding there. Of course, you would use Bool Values to make it happen since, it could get pretty glitchy if you didnā€™t.

1 Like

Basically I think the most future-proof per se, would be to loop through all the buttons:

for _, button in pairs(buttons) do
 if button:IsA(ā€œTextButtonā€) then
  button.Activated:Connect(function()
   for _, frame in pairs(frames) do
    if frame.Visible == true then
     frame.Visible = false
    end
   end
   frame.Visible = true
  end)
 end
end

Sorry for the formatting, Iā€™m typing this on mobile.

2 Likes