1
\$\begingroup\$

I am developing a new Roblox game where you can setup and control you're own virtual machine using SurfaceGUIs on a modeled screen. I am trying to make a confirmation GUI where if you click YES, then it starts the VM, and if you click NO, then it closes the GUI and doesn't start a VM. But when I click on NO, nothing happens! Here is my code:

local gui = script.Parent.Parent
local button = script.Parent

local function cancel()
    gui.Visible = false
end

button.Activated:Connect(cancel())

Please help!
P.S: The confirmation frame is in the ScreenGUI, the button is in the frame, and the LocalScript is in the button.

\$\endgroup\$
3
  • \$\begingroup\$ This seems to be clearly explained in the documentation. Look in particular at how many parentheses are used in the Connect() call. \$\endgroup\$ Commented Jun 22, 2020 at 14:13
  • \$\begingroup\$ I just copyed the code from the docs to my code and made a few edits, and now it works! Thank you! \$\endgroup\$ Commented Jun 22, 2020 at 14:16
  • 4
    \$\begingroup\$ Please share your solution as an Answer then. \$\endgroup\$ Commented Jun 22, 2020 at 14:18

1 Answer 1

1
\$\begingroup\$

Instead of connecting your event to a FUNCTION, you are calling it.

I'll leave a sample on how to correctly use it

local Button = ... --where your button is located

local function Cancel()
  --code 
end

Button.MouseButton1Click:Conect(Cancel)

MouseButton1Click is an event which fires after the GUI BUTTON is clicked.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.