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

How do I make a Gui Button work?

I've been having trouble making TextButtons work. I know how to script a bit, but the buttons just aren't working. I probably have messed up a Connection line or something. Here's my code:

ScreenGui = script.Parent.Parent.Parent
Button = script.Parent
ShopBG = ScreenGui.ShopBG

Button.MouseButton1Clicked:connect(function(onClick)
	if ShopBG.Visible == false then
		ShopBG.Visible = true
	elseif ShopBG.Visible == true then
		ShopBG.Visible = false
	else
		print("An error has occured with the Shop Opening Script.")
	end	
end)

The script is just to open the Shop when you click a Button. When I click it, nothing happens.

Screenshot of my Hierarchy: http://gyazo.com/3a7c744ee52af2dc1d4c7a7a024882ed

4 comments

0

Is your hierarchy correct?

0

It should have been, but I made it game.StarterGui etc etc to be sure. Didn't make the button work then.

0

Oh, and also, it's a LocalScript. That shouldn't affect anything right?

0

Local script is whats needed in this case.

1 answer

All you need to do is take 'onClick' out of line 5. You can't put parameters into a connect statement directly, and that's not a parameter anyways. The resulting line should look like this

Button.MouseButton1Click:connect(function() --also, you needed click, not clicked.

2 comments

0

Still didn't work. I added a screenshot of my Hierarchy into it, so maybe I messed something up there. Respond with a new answer or edit that one if possible, thanks. :)

0

Hierarchy is good. Are there any errors?

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