So my script is in a button with a clickdetector in the button as well. I have multiple GUIs in screen and what I want my script to do is, if at least one child of screen has the Visible property set as true, I want it to change all children of screen to Visible.false. Currently this script only works when there's just one child in screen. Here's what it should do: it serves as a power button for a monitor SurfaceGui that checks if any child of SurfaceGui is visible. If at least one child is Visible, it changes the Visible property of every child of SurfaceGui to false. else, it makes Monitor visible and makes the textBox (a child of Monitor) rotate between "Booting...", "Booting..", and "Booting." three times before saying "Welcome." Here's the code:
local screen = script.Parent.Parent.Monitor.SurfaceGui local label = screen.Monitor.TextLabel function onClicked(playerWhoClicked) for i, child in pairs(screen:GetChildren()) do if child.Visible == true then for i, child in pairs(screen:GetChildren()) do child.Visible = false end else screen.Monitor.Visible = true label.Visible = true for i = 1, 3 do label.Text = "Booting." wait(.5) label.Text = "Booting.." wait(.5) label.Text = "Booting..." wait(.5) if i == 3 then label.Text = "Welcome" wait(1) label.Visible = false i = 1 end end end end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
You can completely change the script if necessary, as long as there are instructions on what to rename and such. I think the problem is that if one child is visible, but another isn't visible, it's running both the Booting screen and making all children invisible. As always I accept the first working answer, thanks in advance.
As you are going through the children on the screen, you are either setting every child's visible property to false or running the booting code. This means it will run through the booting code for every single non-visible child.
Instead of this, you could simply keep track of whether a visible child has been encountered and simply set the remaining children to false if an occurrence happened, otherwise running you booting code:
local screen = script.Parent.Parent.Monitor.SurfaceGui local label = screen.Monitor.TextLabel script.Parent.ClickDetector.MouseClick:connect(function(playerWhoClicked) local isOn = false for i, child in ipairs(screen:GetChildren()) do if isOn or child.Visible then child.Visible = false isOn = true end end if not isOn then -- booting code end end)