Is there more than 1 way to disconnect an event?

local p
p = game.Players.PlayerAdded:Connect(function(player)
print(player.Name)
p:Disconnect()
end)

this is the only way I know how. but i’d like to know if there’s an easier way to do this especially if i need to add multiple events for like 30 things (just an example). maybe self:Disconnect()? would this work?

1 Like

There are libraries that allow you to wrap around RBXSignals and adding new methods like :Once(function()

1 Like

By libraries are you referring to community sources? If so I’m unfamiliar with this and I’d rather know if Roblox has their own alternatives.

1 Like

There’s something called clean up modules, they’re self explanatory, you add items or tasks to a table and you call up a clean up method (either destroys or diconnects the tasks)

some example modules:

Maid,
Janitor,
Hobo,
eWhore

1 Like

Here’s a tutorial on a good cleanup module like @lV0rd suggested

2 Likes

Once is already a built-in method


@Wyzloc Calling Disconnect or having the event disconnect automatically after the first fire (using Once) are the only ways to disconnect an RBXScriptSignal

1 Like

Just add connections to an array, loop through them, and disconnect them.

Yeah that was the only alternative I can come up with that doesn’t involve using other people’s work. I rly just want my code to be simple which is why I’m trying to figure out if there’s more ways to do this. I’ll keep researching regardless but if I can’t find anything I’ll just use arrays or that maid thing.

Internally it does the exact same thing as what I just mentioned.

I dont use a maid because it is more complicated and achieves the same thing.

1 Like

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