Issue with 'local function' and 'frame.Visible'

Hello, friends!

Today I was trying to create a computer GUI, but when I went to create a command that went back to the main menu, it didn’t work and instead made a different GUI frame visible.

I think this may be a bug, but I’m not able to post in bug reports, and I don’t know how to fix it.
I’ve checked multiple times, and nowhere in the script does it have “CoreController”.

EDIT: Problem is at the bottom!

local function MenuControl()
	Menu.Visible = true
	BootBar.Text = ""
	for i, v in pairs(StartScreen:GetChildren()) do
		if v.Visible == false then else
			v.Visible = false
		end
	end
	for i,v in pairs(Menu:GetChildren()) do
		v.Visible = true
	end
end


   CommandBar.FocusLost:Connect(function(enterPressed, inputObject)
    local result
	if enterPressed then
		if CommandBar.Text:lower() == "disablelasers" or CommandBar.Text:lower() == "deactivatelasers" then
			CommandPrompt.CommandArea["1"].Text = "> Enabling lasers."
			for i, v in pairs(game.Workspace.CoreStuff:GetChildren()) do
				if v.Name ~= "Core" then
					if v:GetAttribute("OnLaser") == false then
						result = false
						CommandPrompt.CommandArea["1"].Text = "> LASERS ARE OFF."
					else 
						result = true 
						CommandPrompt.CommandArea["1"].Text = "> Completed laser disabling."
					end
					wait(2)
				end
			end
			if result == false then
				ChangeLaser:FireServer(CommandBar.Text)
			end
		elseif CommandBar.Text:lower() == "enablelasers" or CommandBar.Text:lower() == "activatelasers" then
			CommandPrompt.CommandArea["1"].Text = "> Enabling lasers."
			for i, v in pairs(game.Workspace.CoreStuff:GetChildren()) do
				if v.Name ~= "Core" then
					wait(2)
					if v:GetAttribute("OnLaser") == false then
						result = false
						CommandPrompt.CommandArea["1"].Text = "> LASERS ARE ON."
					else 
						result = true 
						CommandPrompt.CommandArea["1"].Text = "> Completed laser disabling."
					end
					wait(1)
				end
			end
			if result == true then
				ChangeLaser:FireServer(CommandBar.Text)
			end
		elseif CommandBar.Text:lower() == "back" or CommandBar.Text:lower() == "cancel" then
			CommandPrompt.Visible = false
			MenuControl()  -- Main issue!
		end
	end
	game:GetService("RunService").RenderStepped:Wait()
	CommandBar:CaptureFocus()
end)

sorry if this is hard to understand, i’m not that good at scripting lol :sweat_smile:

Could I see the explorer hierarchy for you GUI? It could be an issue of whether or not the parents of Menu is visible or not when you call MenuControl().

In the video, the only thing that changes is the CoreController visibility, but this photo was taken after the script ran

EDIT: It doesn’t change the CoreController visibility anymore, but I still have the issue.

I’ve looked through this a few times and I’m not really sure why it isn’t working, I’ve only been able to come up with two theories:

  1. Maybe ‘Menu’ isn’t pointing to your menu frame, which would be the reason it’s visibility isn’t being set to true in the explorer.

  2. Somehow, one of your for loops that’s setting the visibility of a GUI element’s children to false is targeting ‘TerminalGUI’.

Again, I’m not positive that one of these is the issue, but it’s the best I could come up with.

I think it was a bug, I was looking around and I saw someone say that “:CaptureFocus()” wasn’t working properly and put a space in the TextBox. Then I put this on it…

 CommandPrompt.Visible = false
			game:GetService("RunService").RenderStepped:Wait()
			MenuControl()

And now it seems to be working perfectly! Thanks for the help.