Can you fire a RbxScriptConnection?

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.

3 Likes

If u wanna print hello after the player touches the part, use remote event if im correct.

1 Like

Hello.

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.

I hope this helped!

1 Like

I’m talking about firing a connected event.

1 Like

only if you are using a remote and bindable function or event

1 Like

I know about bindable events, but is there any way I can fire RobloxConnections? Like Part.Touched:Fire(arguments)

prev reply suppose to answer you question

Well I guess there is no way huh.

You actually can, if im right heres the script

local myEvent = Instance.new(“BindableEvent”)
local myConnection = myEvent.Event:Connect(function()
print(“Hello, world!”)
end)

myEvent:fire()

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.

RBXScriptConnection | Documentation - Roblox Creator Hub
RBXScriptSignal | Documentation - Roblox Creator Hub

1 Like

Change this layout:

Event:Connect(function()

end)

To this layout:

local function test()

end

Event:Connect(test)

-- later:
test()

I know, but that’s not what I’m trying to do. I already found a solution for what I was aiming for. Thank you all.

It would help everybody if you posted the solution.

1 Like

My thread wasn’t about that. It was about firing NORMAL events, not bindable events. That’s why I didn’t pick yours as the solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.