I’m creating a main menu GUI and within the main menu I am creating a team selector and I want the gui to fully close.
The issue is that whenever I execute my script, it only closes the frame parenting my image button leaving the main menu tab open I have a feeling it might be the organization of my gui or maybe the script.
I have tried chat GPT also tweeking the script by myself and it didnt solve the issue
local Players = game:GetService(“Players”)
local Teams = game:GetService(“Teams”)
local player = Players.LocalPlayer
local gui = player.PlayerGui:WaitForChild(“ScreenGui”)
local function closeFrames(frame)
– Close the given frame and all its descendants
for _, child in ipairs(frame:GetDescendants()) do
if child:IsA(“Frame”) then
closeFrames(child)
end
end
frame:Destroy()
end
local function assignTeam()
– Assign a team to the player
local team = Teams:GetRandomTeam()
player.Team = team
-- Close all frames under the MainFrame
local mainFrame = gui:FindFirstChild("MainFrame")
if mainFrame then
closeFrames(mainFrame)
end
end
– Find the nested button within the GUI
local nestedButton = gui:WaitForChild(“MainFrame”):WaitForChild(“NestedButton”)
– Connect the nested button to the assignTeam function
nestedButton.MouseButton1Click:Connect(assignTeam)
plr = game.Players.LocalPlayer
local function function name here()
local ui = plr.PlayerGui:FindFirstChild("UINameHere")
if ui then
ui.Enabled = false
else
print(error("No Gui found!"))
end
end
edit: i changed some of the script to make sure theres a ui
He said to me: Sorry for the confusion, I meant i want the GUI to disable fully after a player team is selected under the team selection tab, the script in the post is the script of me attempting to have the GUI close after a team is selected.
he said, that this makes it disable the ui once you join, he needs it after the event happens. Hes stuck on making it close the ui after you mouse click the image button.
You don’t have to access the UI by Local player, it’s so unnecessary to disable the GUI through player if you don’t have remotes to fire or cloning the GUI container to player GUI.
Client is already having access to the GUI and it works by just parenting it with script.Parent, it doesn’t really affect to all clients outside except in the current client (the devices we are using)
Disabling GUI container would be your solution when you don’t need them now, scripts however will still run if it doesn’t get disabled yet.
--script inside a GUI container (ScreenGui)
local GUI = script.Parent
GUI.Enabled = false --completely hidden
also i recommend merging those script in one line as they work without having to place them in each buttons, they don’t only run in a button as long as you assign them correctly