Help With UI Buttons

What are you attempting to achieve?

I am trying to get a GUI frame that loads when a button is clicked (very simple - I’ve done it successfully before).

What is the issue?

Because my first UI dev (who made the icons in the bottom right) did not make them buttons, I put a button over the icon, made it invisible and inserted the script in that button. When clicked, the settings frame will not appear.

What solutions have you tried?

There isn’t much I can try. Both my current UI dev and I have looked over the script and it seems to be fine. I have tried changing different settings inside of the button properties to no avail.

I am not a skilled scripter, so I apologize if this is a really simple problem. I am unsure if my script or my game is at fault in this circumstance. Relevant pictures below.

Screenshot%20(202) Screenshot%20(203)

The first picture is the script located under StarterGui.NewGui.Buttons.SettingsButton. The other two are of the frame and button set-up.

local open = false

script.Parent.MouseButton1Click:Connect(function()
	if frame.Visible == true then
		frame.Visible = false
	else
		frame.Visible = false
	end
end)

^Script written if you want to test it.

Here is the game if you would like to see the UIs.

Thank you!

When you say this, do you mean you made the Button’s Visible property to false or you changed the transparency?

1 Like

I changed the transparency. In retrospect, that wording was a bit confusing.

1 Like

What’s the ZIndex on the invisible button in relation to the frames that it should be covering?

1 Like

The invisible button was at 1, while the settings icon was 3. I changed them both to 3 if that helps.

The Button needs to have a higher ZIndex than the Icon.

1 Like

I made the Zindex 5 and the frame still will not appear.

1 Like

What frame? Instead of making your button transparent right now, try making its transparency to 0 so you can see if your mouse has the ability to click the button. Keep in mind that a higher ZIndex means the closer it is to the top of the screen.

Edit: you can short hand your script by doing frame.Visible = not frame.Visible instead of the 5 lines in the middle.

1 Like

Well, there is a noticeable mistake in the code:

if frame.Visible == true then
		frame.Visible = false
	else
		frame.Visible = false --same thing as before
end

The problem is that you are setting Visible to false, regardless of if the frame is Visible or not, so it will never become visible again. Try changing to:

if frame.Visible == true then
		frame.Visible = false
	else
		frame.Visible = true
end
3 Likes

The settings frame that I am trying to open.

You’re right, can’t believe I missed that. Thank you!!

Thanks for the additional help, too, Qxest.

1 Like

Guess I celebrated too soon – it only works in Studio. When playing the real game, the GUI is still broken. Any idea why this could be? I’m quite sure I have saved the game.

You might need to use WaitForChild(), e.g. local frame = script.Parent.Parent.Parent.Menus:WaitForChild("Settings")

Parent the textbutton to the frame, and then move it over top of the button. When the UI changes resolution things get moved around, Hence why it works in studio but not game. Always put Elements in frames or theyll most likely end up in odd places.

I just did that and it still does not work. Updated the script to:

local frame = script.Parent.Parent
local open = false

script.Parent.MouseButton1Click:Connect(function()
	if frame.Visible == true then
		frame.Visible = false
	else
		frame.Visible = true
	end
end)

Hello!

The game was saved or published? Saving is that tiny box that usually appears when you press X. Publishing is with Alt + P.

You can make that code shorter as well.

local frame = script.Parent.Parent
local open = false

script.Parent.MouseButton1Click:Connect(function()
	frame.Visible = not frame.Visible
end)

If it still doesn’t work, have any errors displayed in the console?

It was saved and published.

The shortened script doesn’t work, either.

No errors.

This is what I got from the code

The first error looks like you are looking for LocalPlayer via game.LocalPlayer, change it to
game:GetService("Players").LocalPlayer

The second error looks like your doing something to Frame.IsOpen, if your changing the value of “IsOpen”, do something like Frame.IsOpen.Value

Make the buttons transparency 0, then publish and see where it’s at and then click

Oddly, the button seems to have disappeared (transparency is at 0 here). I’ll make another button and try again.