How would I go about scripting all children of a Scrolling Frame to be visible = false without individually coding each tab?

Hey friends!

ETA: I’m a noob when it comes to scripting, I’ve got the basics down-ISH but otherwise it’s a bit over my head. Yes I’ve checked the resources available to me but I need it explained to me like I’m 5 lol.

I’ve found myself stuck while scripting my Character Creation GUI.

Currently, I've got my set up as such:

And this is my 'back' button for them to return to the previous list

`local mainMenu = script.Parent.Parent.Parent.MainMenu
local hairMenu = script.Parent.Parent.Parent.Hair
local backButton = hairMenu:FindFirstChild(“BackMain”)

script.Parent.MouseButton1Click:Connect(function()
hairMenu.Visible = false
mainMenu.Visible = true
if backButton then
backButton.Visible = false
end
end)`

I’ve got this issue where when I click an option, and it shows the colors, and then click the back button, everything is great UNTIL I choose the next option. Then basically it’s showing the new options on TOP of the old options (i.e. the old options should’ve been made visible = false but it’s not.)

Now I know where I went wrong, and that I’m technically setting the scrolling frame holding the colors to false and not the actual option, so of course they’re gonna layer.

My QUESTION is this:

Is there a way for me to code this so that I can reference all the children of the scrolling frame and set their visibility to false without going in and individually setting variables?

This is what I mean by setting individual variables if it's not clear:

If it’s important, here’s a video of the specific issue in practice.

Thanks in advance!

local children = scrollingframe:GetChildren()
for key, value in pairs(children) do
     value.Visible = true
end

Forgot to mention that this loop will run through every children of instance, scrolling frame for example and you can do something with each of them.

1 Like

Okay, gotcha.

Is this correct in usage? I updated the variable so it matched what I got going on here:

local mainMenu = script.Parent.Parent.Parent.MainMenu
local hairMenu = script.Parent.Parent.Parent.Hair
local colors = script.Parent.Parent.Colors
local button = script.Parent

button.MouseButton1Click:Connect(function()
	hairMenu.Visible = true
	colors.Visible = false
	local children = colors.ScrollingFrame:GetChildren()
	for key, value in pairs(children) do
		value.Visible = false
	end
end)

Yes it is. By the way :GetChildren() returns a table that contains all the children of instance, so you can use the same loop with normal tables

1 Like

Oh cool okay.

You said the way I’ve got it set up is correct, but it’s not working in my playtest.

Is your scrolling frame contains something that is cannot change it visible?

1 Like

WAIT ignore me I had it in the wrong button smh.

It works fine. Thank you very much!!!

1 Like

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