Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a Gui Button work?

Asked by 9 years ago

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

0
Is your hierarchy correct? Ekkoh 635 — 9y
0
It should have been, but I made it game.StarterGui etc etc to be sure. Didn't make the button work then. SlickPwner 534 — 9y
0
Oh, and also, it's a LocalScript. That shouldn't affect anything right? SlickPwner 534 — 9y
0
Local script is whats needed in this case. GoldenPhysics 474 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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.
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. :) SlickPwner 534 — 9y
0
Hierarchy is good. Are there any errors? GoldenPhysics 474 — 9y
Ad

Answer this question