Hello fellow scripters, I have a question to ask. Is it possible to get/fire the function of a RbxScriptConnection? For example, let’s define a localscript that adds a .Touched connection to a part, which prints “hello” when it’s fired. And let’s say I have another localscript. Can I get/fire the function of this connection?
This question has begged my mind for a long time because exploiters can do this. I wonder if I can replicate this to possibly see how it works.
If you’re wondering you can call a function in a script from another script, then the answer is yes.
Bindable events are events that connect one script to another. You can call BindableEvent:Fire() on one script, and BindableEvent.Event to create a connection.
No, you can’t get the function from a connection nor fire the connection yourself. I think the best approach is to define the connected function as a separate variable and call it yourself.
function foo()
print("Hello World")
end
script.Parent.Touched:Connect(foo)
foo()
Since you want to share it across different scripts, consider storing this function in a ModuleScript.
Also, perhaps, you would have more control over it if you used a library like Signal | RbxUtil (sleitnick.github.io). But even with this, you can’t get the function from the connection.