Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to loop through Gui frames to check if they're visible or not?

Asked by 3 years ago

Hello! I'm pretty new to programming and I'm trying to create an Gui script which don't need an script in every frame. This is one of many options i've tried so far:

local MainGui = script.Parent.MenuGui

MainGui.Position = UDim2.new(0.5,0,0.5,5)
MainGui.AnchorPoint = Vector2.new(0.5,0.5)
MainGui.Size = UDim2.new(0, 500, 0, 500)
local opvv = script.Parent.opv.Value


for i,v in pairs(script.Parent.MenuGui:GetChildren()) do
    v.Gui.Visible = false
    v.Size = UDim2.new(0,200,0,50)
    v.MouseButton1Click:Connect(function()
        print(v.Name)
        local gui = v.Gui
        if gui.Visible == false then
            gui.Visible = true
            opvv = opvv + 1
            while true do wait()
                if opvv >= 2 then 
                    gui.Visible = false
                    opvv = opvv - 1
                end
            end
        elseif gui.Visible == true and opvv == 1 then
            gui.Visible = false
        end
    end)
end

2 answers

Log in to vote
0
Answered by 3 years ago

idk how to scan all of them but I think this is good:

while wait() do
      if fram.Visible == true then
              --anything
      end
end
0
If you don't know how, then refrain from replying. radiant_Light203 1166 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

You're already looping through the gui's children. The problem is that you're setting up a while do loop inside of the function and this prevents the rest of the children from being iterated through.

You can either use coroutines (I suggest you don't), or instance:GetPropertyChangedSignal() to check when a gui's visible property changes and perform functions accordingly.

Answer this question