auto
Infer the type from the initializer. Prefer explicit types on parameters and struct fields.
Syntax
Section titled “Syntax”auto players = GetService<Players>();auto janitor = new Janitor();auto [ok, result] = pcall(fn);Parameters
Section titled “Parameters”None.
Return value
Section titled “Return value”Whatever the initializer produces.
Luau emit
Section titled “Luau emit”local name = … (Luau annotation when known)
Description
Section titled “Description”Inferred for new Class(...), GetService<T>(), datatype constructors, and destructuring.
Do not use auto as a replacement for a public API type.
Example
Section titled “Example”auto coins = new IntValue(leaderstats);Emits:
local coins: IntValue = Instance.new("IntValue")coins.Parent = leaderstatsSee also
Section titled “See also”new · GetService · destructure