I have created a textbutton that when clicked, can open and close a frame (very simple). However, after some editing and improvements, I now have a GUI that consists of a complicated frame, as well as external text buttons (meaning not within the frame) How can I “add” those textbuttons to my open-close script, so they open and close with the frame too?
I have a short video showing that they are separate, and my entire open-close script below.
local frame = script.Parent.Parent.Pages -- Replace "TESTFRAME" with your frame name.
local textbutton = script.Parent.Parent["Dances Button"] -- Replace "OPENCLOSETESTFRAME" with your TextButton name.
local open = script.Open
local close = script.Close
open.Value = true
textbutton.MouseButton1Click:Connect(function()
if open.Value == true then
frame.Visible = true
open.Value = false
close.Value = true
textbutton.Text = "Close Dances" -- Change to what you want to say.
elseif close.Value == true then
frame.Visible = false
open.Value = true
close.Value = false
textbutton.Text = "Dances" -- Change to what you want to say.
end
end)
The above script, as of now, just works to open and close the frame, not the textbuttons. To sum up my post, I need guidance on how to add the open and close functions to the three textbuttons that are not apart of the original frame.
Are the not hidden UI elements descendant of the frame? You can put them in there, if they aren’t, and then just say Frame.Visible = false, it works for all descendants.
They are not descendants of the frame, they are actually located as the children of the ScreenGUI. And when I move them wierd GUI stuff happens, so I’m not looking to do that.
It’s not exactly what you have to paste in, it was just an example of what function you should use;
The Gui must be changed to which gui the buttons are stored in for example, if they are stored in: game.Players.LocalPlayer.PlayerGui.Buttons then change it to that: for _,v in pairs(game.Players.LocalPlayer.PlayerGui.Buttons:GetChildren()) do
Ok so this is my script now and still the same issue. I’m not super experiences so I’m not sure what is wrong now, but i feel a lot closer.
local gui = script.Parent.Parent.Parent.ScreenGui
local frame = script.Parent.Parent.Pages -- Replace "TESTFRAME" with your frame name.
local textbutton = script.Parent.Parent["Dances Button"] -- Replace "OPENCLOSETESTFRAME" with your TextButton name.
local open = script.Open
local close = script.Close
open.Value = true
for _,v in pairs(script.Parent.Parent.Parent.ScreenGui:GetChildren()) do
textbutton.MouseButton1Click:Connect(function()
if open.Value == true then
frame.Visible = true
open.Value = false
close.Value = true
textbutton.Text = "Close Dances" -- Change to what you want to say.
elseif close.Value == true then
frame.Visible = false
open.Value = true
close.Value = false
textbutton.Text = "Dances" -- Change to what you want to say.
end
end)
end
textbutton.MouseButton1Click:Connect(function()
if open.Value == true then
for _,v in pairs(script.Parent.Parent.Parent.ScreenGui:GetChildren()) do
v.Visible = true -- Unhide every button
end
frame.Visible = true
open.Value = false
close.Value = true
textbutton.Text = "Close Dances" -- Change to what you want to say.
elseif close.Value == true then
for _,v in pairs(script.Parent.Parent.Parent.ScreenGui:GetChildren()) do
v.Visible = false -- Hide every button
end
frame.Visible = false
open.Value = true
close.Value = false
textbutton.Text = "Dances" -- Change to what you want to say.
end
end)
end
local gui = script.Parent.Parent.Parent.ScreenGui
local frame = script.Parent.Parent.Pages -- Replace "TESTFRAME" with your frame name.
local textbutton = script.Parent.Parent["Dances Button"] -- Replace "OPENCLOSETESTFRAME" with your TextButton name.
local open = script.Open
local close = script.Close
open.Value = true
textbutton.MouseButton1Click:Connect(function()
if open.Value == true then
for _,v in pairs(script.Parent.Parent.Parent.ScreenGui:GetChildren()) do
v.Visible = true -- Unhide every button
end
frame.Visible = true
open.Value = false
close.Value = true
textbutton.Text = "Close Dances" -- Change to what you want to say.
elseif close.Value == true then
for _,v in pairs(script.Parent.Parent.Parent.ScreenGui:GetChildren()) do
v.Visible = false -- Hide every button
end
frame.Visible = false
open.Value = true
close.Value = false
textbutton.Text = "Dances" -- Change to what you want to say.
end
end)
Pretty strange, it should work, maybe it’s related to your ui, or I messed up the visible lines:
If I did, just replace it between the other:
Anyways, try this, a better method:
textbutton.MouseButton1Click:Connect(function()
for _,v in pairs(script.Parent.Parent.Parent.ScreenGui:GetChildren()) do
if open.Value == true then
v.Visible = true -- Unhide every button
frame.Visible = true
open.Value = false
close.Value = true
textbutton.Text = "Close Dances" -- Change to what you want to say.
elseif close.Value == true then
v.Visible = false -- Hide every button
frame.Visible = false
open.Value = true
close.Value = false
textbutton.Text = "Dances" -- Change to what you want to say.
end
end
end)
local open = true
script.Parent.MouseButton1Click:Connect(function()
if open == true then
open = false
script.Parent.Visible = false
script.Parent.Parent.Whateverthenameofyourtextlableis.Visible = false
else
open = true
script.Parent.Visible = true
script.Parent.Parent.Whateverthenameofyourtextlableis.Visible = true
end
end)
Parent the textlabels to the frame and that’s all you have to do. If it messes up the position, correct the position. Then do this:
local open = true
script.Parent.MouseButton1Click:Connect(function()
if open == true then
open = false
script.Parent.Parent.Visible = false
else
open = true
script.Parent.Parent.Visible = true
end
end)
You should try checking that the children:IsA(‘TextButton’) or a guiObject if you are going to add different gui objects when looping.
textbutton.MouseButton1Click:Connect(function()
for _, buttons in pairs(gui:GetChildren()) do
if buttons:IsA("TextButton") and buttons ~= textbutton then
if open.Value == true then
buttons.Visible = true
frame.Visible = true
open.Value = false
close.Value = true
textbutton.Text = "Close Dances" -- Change to what you want to say.
elseif close.Value == true then
buttons.Visible = false
frame.Visible = false
open.Value = true
close.Value = false
textbutton.Text = "Dances" -- Change to what you want to say.
end
end
end
end)
if buttons:IsA("TextButton") and buttons ~= textbutton then
On this line I blacklist your textbutton from the for loop, so it doesn’t change its visible property. Since you have 2 textbuttons, you would need to blacklist the other one too using the not equal to operator.
if buttons:IsA("TextButton") and buttons ~= textbutton and buttons ~= 'Second_Button' then