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

Is there a way of changing the connection of an event listener without disconnecting it?

Asked by
noposts 75
6 years ago

The current and only way with my knowledge of how to change the part the event is listening to is by disconnecting the event and then reconnecting it with another afterwards. It goes something like:

local part = workspace.Part
local part2 = workspace.Part2

local function on()
    print "touched"
end
local connection = part.Touched:Connect(on)

wait(5)
connection:Disconnect()
part2.Touched:Connect(on)

I do not know if there's any other way of reconnecting an event more efficiently to another part and I've tried thinking of alternatives but failed so then I decided to ask here and hope that my question is understood.

0
Anything wrong with disconnecting it? mattscy 3725 — 6y

Answer this question