How can i make this text button work correctly?

I am trying to make a funcionaly textbutton that when got clicked display a specific frame and in that frame the button is not visible, but the script i use doesn’t work.

image

Script:
local Frame = script.Parent.MainMenu
local Button = Frame.TextButton

Button.MouseButton1Click:Connect(function()
Button.Visible = not Button.Visible
end)

Does the button have a higher ZIndex than rest of the items in MainMenu?

and you define “Frame” with

local Frame = script.Parent.MainMenu;

Is this from the visible local script? if so, “MainMenu” will be script.Parent

I’d recommend reading the error you get in the Output. Take a look at your first line. What’s the Parent of script and does it have a child called MainMenu?

1 Like

What is happening is that you are making the button itself invisible:

Here is my try on fix of the code:

local Frame = script.Parent.MainMenu
local Button = Frame.TextButton

Button.MouseButton1Click:Connect(function()
    Button.Visible = not Button.Visible
end)

But this also would be bad, since the button is a child of Frame, meaning that if you set the MainMenu/Frame’s visibility to false, the button would also become invisible, consider making some changes.

What’s the error coming from the output? Is there one?

Also try local button = Frame.Parent.TextButton

it says Main Menu is not a valid member of frame

image

Since the script is a children of MainMenu itself, why use script.Parent.MainMenu?

This is why its causing that error, you should use script.Parent instead.

1 Like