Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Kind-of-dropdown menu for GUI not functioning?

So I honestly suppose this is broken because I am bad at scripting. I tried but clearly it doesn't work :P

So I have this 'Menu' GUI, with two invisible GUIs below it. I intend so that when I click on the Menu button, the two GUIs below it, Donate and Information, will become visible, and of course clickable. I suppose it's because I'm confused on how MouseButton1Down works.

If you need this AT ALL: http://prntscr.com/74k68o

My current scripting that I attempted:

print("Menugui dropdown-initiate") 
MenuHeader = game.StarterGui.ScreenGui.Frame.MenuHeader
Donate = game.StarterGui.ScreenGui.Frame.Donate
Info = game.StarterGui.ScreenGui.Frame.Information

function Dropdown()
	
	MenuHeader.MouseButton1Click:connect(Dropdown)
	Info.Visible = true
	Donate.Visible = true
	
	MenuHeader.MouseButton1Click:connect(Dropdown)
		Info.Visible = false	

	
	end

script.Parent.MouseButton1Down:connect(Dropdown)

I would appreciate if you could help me out. Thanks!

3 comments

0

The 'MouseButton1Down' event fires when an 'TextLabel' or 'ImageLabel' is clicked on (MouseButton1Down WIKI Document: http://wiki.roblox.com/index.php?title=MouseButton1Down), also, please tab your code correctly. :)

0

They are textbuttons, and in some other work people have coded for me, that same event has fired with a text button

0

Whoops, I meant 'ImageButton' and 'TextButton', sorry. :c

3 answers

✓ Accepted answer
function Dropdown()
	
	MenuHeader.MouseButton1Down:connect(Dropdown)
end

This part causes the script to flip out. You have an event that fires when you click a button, but inside of the function, is the same exact event.

So, what the script is doing is this

function Dropdown()
	Dropdown()
end
Dropdown()

It's causing a loop, that's why it doesn't become visible. Imagine your code like this

while true do
	wait(1)
	print("You'll never destroy me!")
end
script:Destroy()

It will never get to the line with :Destroy() because the while loop doesn't end.

When attempting to change a GUI for a user, you will need to access the GUIs through their PlayerGui object. When changing a GUI through StarterGui, the GUI won't appear changed until you reset and it will be changed for everybody. In order to fix this, please use a LocalScript and access their PlayerGui throguh game.Players.LocalPlayer.PlayerGui. If you have any other questions, feel free to ask me.

2 comments

0

LocalPlayer @ PlayerGui don't exist until you test-play the game

0

You have to have a player in the game for GUIs to do anything.

Try this

MenuHeader = script.Parent.Frame.MenuHeader
Donate = script.Parent.Frame.Donate
Info = script.Parent.Frame.Information

insted of the old things I can make the GUI for you if you want just give me a model.

This discussion is preserved as it was. New answers, comments, and votes are closed.