func (...)
Anonymous callback. There is no C++ capture list — CL++ has no pointers to capture. Luau still closes over outer locals.
Syntax
Section titled “Syntax”func (T arg) { }func () { }func cb = func () {};Parameters
Section titled “Parameters”None.
Return value
Section titled “Return value”A function value.
Luau emit
Section titled “Luau emit”function(arg: T) … end
Description
Section titled “Description”func is both the type and the keyword that starts an inline callback. Passing a method by name from inside Class:: binds self: function(...) self:OnPlayer(...) end.
Keep Instances alive with Janitor; closures do not own Roblox lifetime. Do not write func [](…) or []() { }.
Example
Section titled “Example”players.PlayerAdded~>Connect(func (Player playerEntered) { post("New player: " .: playerEntered.Name);});Emits:
janitor:Add(players.PlayerAdded:Connect(function(playerEntered: Player) print("New player: " .. playerEntered.Name)end), "Disconnect")