I am on tablet so I am not doing good, but on my computer I have a button and I use the script below in the button. Now I tried both Localscript and Script, but neither of them work! The script works in studio mode, but not in player mode. This is a cool thing to my game crop farm tycoon with this you use it as the tycoon button, and you use another one to change the hover color! PLEASE HELP!
And remember that THIS IS A SURFACE GUI WITH A BUTTON INSIDE OF IT! just to not make a mistake and redo it xD
script.Parent.MouseButton1Click:Connect(function(onClick)
script.Parent.Parent.Visible = false --Just an example not the real thing onClick...
end)

2 comments
try deleting the "onClick" which isn't actually a name for your function, rather a parameter (which the event "MouseButton1Click" does not send any)
As it works in game but not in studio, try making all of your variables local?