The best way I could’ve come up with doing this is using CollectionService and setting all the frames I want to make invisible with a unique tag, because I don’t want to hide the entire GUI’s.
Then for easier use, putting the command in modulescript, something like this:
module.closeGuis = function(keepOpen)
local CollectionService = game:GetService("CollectionService")
local taggedFrames = CollectionService:GetTagged("Frames")
for _, Frame in pairs(taggedFrames) do
if Frame.Name ~= keepOpen then
Frame.Visible = false
end
end
So it will basically make invisible all the frames and the keepOpen will be the one that should be opened.
Then in each script I will use when opening a GUI: module.closeGuis(what I wish to open)
Does anyone have a better way to do it? Will appreciate any replays.
Your making this so much more complicated than it should be. You don’t need to use CollectionService. Just use a table to get all ScreenGui descendants from PlayerGui and use check if that descendants name is not keepOpen then turn their visibility off.
I don’t think this is a bad idea, it’s a good way to quickly reference all of the Frames you want to close. The only possible change I’d suggest is only tagging the Frames you want to close when the game begins.
That way you wouldn’t have to name all of your Frames to keep open as “keepOpen”, as the taggedFrames would only contain the Frames you want to close.
Granted, actually implementing this check may be more taxing then doing things this way though, it depends on how you get all of the Frames you want to close. (So it’s up to you really)
Thanks for your replay, I had that in mind too but I figured that it might be easier for it to know what it’s looking for by the unique tag instead of going through all the descendants including the one’s that are irrelevant?
local Descendants = game.Players.LocalPlayer:WaitForChild('PlayerGui'):GetChildren()
for i,v in pairs(Descendants) do
if v.Class = ScreenGui then
--Make it invisble here
end
end
You can use this script. What this script does: Its getting everything in playergui and searching inside guis in playergui and if in playergui is a frame then it makes this frame invisible. This script worked for me.
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
for i, v in pairs(plr.PlayerGui:GetChildren()) do
for i, c in pairs(v:GetChildren()) do
if c:IsA("Frame") then
c.Visible = false
end
end
end
end)