Skip to content

func (...)

Functions

Anonymous callback. There is no C++ capture list — CL++ has no pointers to capture. Luau still closes over outer locals.

func (T arg) { }
func () { }
func cb = func () {};

None.

A function value.

function(arg: T) … end

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 []() { }.

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")

func · Connect · function · this