~> (janitor Connect / Once)
~> (janitor Connect / Once)
Section titled “~> (janitor Connect / Once)”Subscribe and give the connection to Janitor. ~>Connect and ~>Once only.
Syntax
Section titled “Syntax”signal~>Connect(fn);signal~>Once(fn);Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
fn | func | Listener. |
Return value
Section titled “Return value”The connection (also stored on the janitor).
Luau emit
Section titled “Luau emit”janitor:Add(signal:Connect(fn), "Disconnect")
Description
Section titled “Description”Looks up janitor local, self.janitor, or a synthetic __janitor. In void init(), __janitor also gets game:BindToClose.
Bare ::Connect does not register with Janitor. Prefer ~> in production.
Once disconnects after the first emission.
Example
Section titled “Example”players.PlayerAdded~>Connect(func (Player player) { post("Connected and managed automatically!");});players.PlayerAdded~>Once(func (Player player) { post("First player only");});Emits:
janitor:Add(players.PlayerAdded:Connect(function(player: Player) print("Connected and managed automatically!")end), "Disconnect")janitor:Add(players.PlayerAdded:Once(function(player: Player) print("First player only")end), "Disconnect")See also
Section titled “See also”Connect · Once · Fire · init · header-janitor