Im trying to make a select tab thing for my avatar editor that im working on but it's not working

so there is like tabs for like hats, shirt , scale, etc and i need help so like if you select hats it come up with a tab of hats under it
like so:
tablesmaybe
I started with making a frame for each one and added a local script to hats open button the goal of the script is to check to see if the other seven buttons are visible if so then it will make them not visible and return making the hats tab visible pretty simple, but it’s not working

local hats = script.Parent.Parent.HairFrame
local hair = script.Parent.Parent.HairFrame
local shirt = script.Parent.Parent.ShirtsFrame
local pants = script.Parent.Parent.PantsFrame
local back = script.Parent.Parent.BackFrame
local skin = script.Parent.Parent.SkinFrame
local body = script.Parent.Parent.BodyFrame
local scale = script.Parent.Parent.ScaleFrame

script.Parent.MouseButton1Click:Connect(function()
	if hats.Visible == false then
		hats.Visible = true
	end
	if hair.Visible == true then
		hats.Visible = false
	end
	if shirt.Visible == true then
		hats.Visible = false
	end
	if pants.Visible == true then
		hats.Visible = false
	end
	if back.Visible == true then
		hats.Visible = false
	end
	if skin.Visible == true then
		hats.Visible = false
	end
	if body.Visible == true then
		hats.Visible = false
	end
	if scale.Visible == true then
		hats.Visible = false
	end

end)

please tell me what i’m doing wrong

Thanks, Joesiuh

I’d recommend this instead.

local frameContainer = -- the parent of the frames

local frames = frameContainer:GetChildren()

for i, frame in ipairs(frames) do
    frame.MouseButton1Click:Connect(function()
        local newVisible = not frame.Visible -- opposite of what it was (false --> true or true --> false)
        frame.Visible = newVisible
        if newVisible then -- if it's true
            for i, otherFrame in ipairs(frames) do 
                if otherFrame ~= frame then
                    otherFrame.Visible = false 
                end
            end
        end
    end
end
1 Like