Skip to content

: (type / protected call)

Operator

Two jobs: types on names, and Safe Mode calls that cannot crash the script.

age: int = 10;
void Greet(player: Player) { }
player:Kick();
auto child = workspace:FindFirstChild("x");

None.

For a call: the result on success, nil on error. The script keeps running.

local age: number = 10

(function()
local _ok, _r = pcall(function()
return player:Kick()
end)
return if _ok then _r else nil
end)()

Types. Prefix C++ types still work (int age = 10). : is the other spelling: age: int = 10, and name: Type on parameters. In the emitted Luau, every local already uses name: Type.

Protected calls. player:Kick() is Luau-style : and a pcall. Prefer . when the call should throw (player.Kick()). Use : when a missing child, a bad argument, or report must not stop the listener.

Range-for uses in (or : in a different position): for (T x in list).

Bare Table:Key without () still emits Table.Key (old table-key spelling). New code uses .: DataService.Server.

age: int = 10;
Instance child = workspace:FindFirstChild("Missing");
guard (child != null) else {
return;
}

Emits:

local age: number = 10
local child: Instance = (function()
local _ok, _r = pcall(function()
return workspace:FindFirstChild("Missing")
end)
return if _ok then _r else nil
end)()
if not (child ~= nil) then
return
end

pcall · operator-property · operator-method · int