I would like it so only one frame at a time can be seen. Imagine this. 3 buttons. When you click any button it opens a gui. I want it so when you click a button it opens a gui(already done), then when you click another button it closes the guis(First one clicked) frame.
Are they using the same frame? The simplest thing you can do is make one button make the frame visible’s property to true, and the other sets visible to false.
I would like it so that when a button is pressed and another guis frame is opened it will close it out and show the buttons that was just clicked frame. Im not sure how to explain this.
umm…Heres a game that can help you understand what I mean…Click one of the buttons on the left and click another one and you will see the original guy close while the buttons that was just clicked, its frame will open.
That’s how you would do it yea. The way you do it depends on how the Screengui is handled. But if the buttons are all children of the Screengui and the frame to open is a child of the button, something like this would work (The script in question is a localscript inside of the screengui
local gui = script.Parent
for i,v in pairs(gui:GetChildren()) do
if v:IsA("TextButton") and v:FindFirstChildOfClass("Frame") then
v.MouseButton1Click:Connect(function()
for i,f in pairs(gui:GetDescendants()) do
if f:IsA("Frame") and f.Parent:IsA("TextButton") and f.Parent ~= v then
f.Visible = false
end
end
v.Frame.Visible = true
end)
end
end
Let me explain this code
First we get the screengui, then we loop through all its children, if a child is a textbutton and it has a frame inside it, then we connect the MouseButton1Click event to it. What this event does is when the player presses a button, it loops through everything in the screengui and if what it finds is a Frame, its parent is a textbutton and its parent is not the button that was pressed, it makes them invisible, afterwards it enables the frame inside it
local gui = script.Parent
for i,v in pairs(gui:GetChildren()) do
local frame = v:FindFirstChildOfClass("Frame") or v:FindFirstChildOfClass("ImageLabel")
if v:IsA("ScreenGui") and frame and v:FindFirstChildOfClass("TextButton") then
v:FindFirstChildOfClass("TextButton").MouseButton1Click:Connect(function()
for i,f in pairs(v:GetChildren()) do
if (f:IsA("Frame") or f:IsA("ImageLabel")) and f.Parent ~= v then
f.Visible = false
end
end
frame.Visible = true
end)
end
end
The Localcscript taht contains thsi code would have to have StarterGui as its parent
Then I think that’s my fault with the code, guessing how I tried to do it didn’t go so well, another way you could do that is just to connect the event to each one by one, I tried to shorten that but I think it’s better if you do it event by event. I’m not sure what would be the proper way though, I think proably one of those 2 people that are reply have a better answer than I do
Ok so I have read all of the comments, the person above me has a really good way to do this but it may be somehow complicated for some people.
So you will need to place a local script inside the StarterGui and then put your button inside the GUI and then do this
script.Parent.ScreenGui.TextButton.MouseButton1Up:Connect(function)
Frame.Visible = false
Frame2.Visible = false
– and keep on going with your code here and change their names to what you already have