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
idk how to scan all of them but I think this is good:
while wait() do if fram.Visible == true then --anything end end
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.