UI visible scripting problem

Hello,

I’m trying to make a UI button thing.

I’ve never done it before nor know what its called, and I’m kinda stuck.

I want it so the frameUnder will be visible but the others will not.

local screenUI = script.Parent

local frame1 = screenUI.Frame1
local frame2 = screenUI.Frame2
local frame3 = screenUI.Frame3

local textButton1 = screenUI.text1
local textButton2 = screenUI.text2
local textButton3 = screenUI.text3

for _, v in pairs(screenUI:GetChildren()) do
	if v:IsA("TextButton") then
		
		v.MouseButton1Down:Connect(function()
			local frameUnder:Frame = v.frame.Value
			
			frame1.Visible = false
			frame2.Visible = false
			frame3.Visible = false
			
			frameUnder.Visible = not frameUnder.Visible
		end)
		
	end
end

I found a way, not sure if its the best but it works for what I needed. if you have a simpler/easier way let me know!

local screenUI = script.Parent

local frame1 = screenUI.Frame1
local frame2 = screenUI.Frame2
local frame3 = screenUI.Frame3

local textButton1 = screenUI.text1
local textButton2 = screenUI.text2
local textButton3 = screenUI.text3

for _, v in pairs(screenUI:GetChildren()) do
	if v:IsA("TextButton") then
		
		v.MouseButton1Down:Connect(function()
			local frameUnder:Frame = v.frame.Value

			frameUnder.Visible = not frameUnder.Visible
			
			for _, v in pairs(screenUI:GetChildren()) do
				if v:IsA("Frame") then
					if v ~= frameUnder then
						v.Visible = false
					end
				end
			end
			
		end)
		
	end
end

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