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.
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)
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.
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
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.
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)