Change frame visibilities in a single script line

Hey everyone!

I’ve been struggling to find a solution to effiiciently toggle visibility of UI frames in a single script, and I was hoping someone has a solution to this problem.

Here’s an example — for my Admino panel, let’s say there is a Dashboard frame, a Messages frame, and a Moderation frame. When the user selects the “dashboard” button, thus making the “dashboard” frame visible, all other UI frames must be made invisibile through the “Frame.Visible=false” function.

However, there are two ways I can do this — I can either define the “messages” and “moderation” frame through the local function and then lay them out over two lines of a script. Or, if possible, I was wondering if I can do this all at once in a single line of a single script.


As you know a panel contains many, many frames, listing them out line-by-line is simply not an option. I have well over 30 frames and counting as I modify them and attempt to reduce this number but I need an efficient way to toggle visibility without hogging 30 lines of a script.

Let me think about this, I’ll get back to youy.

1 Like

Maybe something like:

if   x: y = z = False
elif y: x = z = False
elif z: x = y = False
1 Like

Thanks! I’ll try this out soon and let you know if it works.

Good luck, let me know if you get any errors!

1 Like

So I tried putting this into a LocalScript within ServerScriptService, before I actually ran the script I got a lot of red underlines …

local x = game.StarterGui.MainUI.MainFrame
local y = game.StarterGui.MainUI.MessagesFrame
local z = game.StarterGui.MainUI.ModerationFrame

if   x: y = z = false
elif y: x = z = false
elif z: x = y = false

end

Can we have the error when you run it, that code was designed for python.

You could use a loop, such as:

for _,v in next,PARENTHERE:GetChildren() do
     if v.Name == openFrame.Name then continue end
     v.Visible = false
end

Or, honestly any loop - this is just the type of loop I prefer to use.

1 Like

I wouldn’t consider that more efficient for this task.

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