Making a button close the current frame that is opened

I won’t leave until you know and solve this problem! Don’t worry man!

If all of this doesn’t last more than an hour I should be able to stay and keep helping

Finally managed to make a working example. Put it in a LocalScript under your Button:

script.Parent.MouseButton1Click:Connect(function()
	for i, v in ipairs(game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):GetChildren()) do
		if v:IsA("ScreenGui") and v:FindFirstChild("Frame") and v.Name ~= "Chat" and v.Name ~= "BubbleChat" then
			v:WaitForChild("Frame").Visible = false
		end
	end
end)

Thanks guys! Heres a model. gimme a sec

@Mista_Noobery
Please look up my latest post as it will solve your issue. Mark it as a solution.

Will fix it and give you the ready version!

Have you checked out my solution???

Here’s a video:

So are you trying to hide all of them when the button is pressed?

Yup it worked. BUT…My slamo checklist has a different opening script…

It has a lot of other scripts and its making it doozy

No not exactly. I want it so when a button is pressed it closes the current guis that is opened.

Oh I see… Ok will try to solve that right now!

@Mista_Noobery

OK, I understand. You only want one Frame at once. Just use my example with a little modified code:

script.Parent.MouseButton1Click:Connect(function()
	for i, v in ipairs(game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):GetChildren()) do
		if v:IsA("ScreenGui") and v:FindFirstChild("Frame") and v.Name ~= "Chat" and v.Name ~= "BubbleChat" then
			v:WaitForChild("Frame").Visible = false
		end
	end
	script.Parent.Visible = true
	script.Parent.Parent:WaitForChild("Frame").Visible = true
end)

The code should be located in LocalScript in Button in the Gui:
structure

Well, You wouldn’t use ScreenGuis to hold the buttons and frames. This would be a better option:

Then use a for loop like so:

local GUIS = script.Parent.Buttons:GetChildren() --gets the children of the folder with all the buttons, must be named "Buttons"
local FrameFolder = script.Parent.Frames:GetChildren() --gets the children of the folder with all the main frames, must be named "Frames"


for _, Uis in pairs(GUIS) do
    if (Uis:IsA("TextButton")) then
        Uis.Activated:Connect(function()
            for _, Frames in pairs(FrameFolder) do
               --set the name of the frame to the exact name of the button, so if the button is named shop, name the frame for it "shop"
               if (not Uis.Name == Frames.Name) then
                   --close other frames
                   Frames.Visible = false
               else
                    --open main frame
                   Frames.Visible = true
               end
            end
        end)
    end
end

I wouldn’t recommend using this with small amounts of frames closing and opening.
Might have gotten your solution but I’m still glad I tried to help.
Oh yeah, script location would be in the main ScreenGui.

Yes. I used it but one of the text buttons don’t work since its off a tutorial and I’m too afraid to tweak it.

Sorry for my mistake. I added one more Parent. Look at my message again and copy the code.

So I’m working on it and I will explain everything in the code! Almost done!

THANKS ALL! Jermartynojm figured it out.

@Mista_Noobery

I’ve finally made a working example of it here: testing baseplate.rbxl (28.1 KB)

Here’s a video:

Mark this as a solution instead of the old one.

1 Like