how do i make a table that stores a function like Button.MouseButton1Up:Connect()
without activating it? is this possible? is there an easy way to store functions like these and be able to connect and disconnect them like binding in CAS?
Well how you choose to reference the function which you pass to RBXScriptConnections is up to you. You can create a table of functions and simply pass the function you need to it, for example.
local ConnectionMethods = {
MyButton1UpMethod = function()
print("Hello, I was clicked!")
end
}
Button.MouseButton1Up:Connect(ConnectionMethods.MyButton1UpMethod)
Alternatively (ModuleScripts):
To create a Module with a table of functions:
local ConnectionMethods = {}
function ConnectionMethods.MyMethod()
print("Hello! You called?")
end
return ConnectionMethods
local ConnectionMethods = require(path.to.ConnectionMethods)
Button.MouseButton1Up:Connect(ConnectionMethods.MyMethod)
You can also store Button.MouseButton1Up
(and other RBXScriptSignals) as its own variable too:
local Button1Up = Button.MouseButton1Up
Button1Up:Connect(ConnectionMethods.MyButton1UpMethod)
The return type for the :Connect()
method is is an RBXScriptConnection, which has a :Disconnect()
method. This is so you can stop a specific event from firing a function when you’re done. Just call :Connect()
again to reconnect the event.
3 Likes
You cannot reconnect disconnected connections, if that’s what you’re asking. You have to create a new connection.
ooooh! thats exactly what i need! tysm
1 Like