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

How do I Make a Function that executes when different GUI Buttons are pressed?

Asked by 4 years ago

I am trying to make the same function occur on different triggers basically. Currently I have something like this within a GUI Button:

function onClicked(GUI)
    --code
end
script.Parent.MouseButton1Click:connect(onClicked)

Can I just add connect statements to this for other GUI buttons in the game like this?

function onClicked(GUI)
    --code
end
script.Parent.MouseButton1Click:connect(onClicked)
game.workspace.otherButton.MouseButton1Click:connect(onClicked)
game.workspace.otherButton2.MouseButton1Click:connect(onClicked)
1
I think so, but I might be wrong. youtubemasterWOW 2741 — 4y
1
That's it! As long as the RBXScriptSignal is valid, you can Connect any function. Please ensure you're using a capital C though, lowercase :connect() is deprecated. Ziffixture 6913 — 4y

Answer this question