Skip to content

Nullable Type

Not Standard In Lua

This type of parameter is not used in standard Lua documentation, and instead exists for Roblox's strongly-typed Luau, which requires certain values to be a very specific type defined by the developer.

Nullable types are assigned to values to state that they are allowed to be nil regardless of their type. They are defined by appending a ? after the name of the type. In strongly-typed Luau, only parameters that are made nullable can be nil.


(number , number? )

Different Than Optional Parameters

Be careful to not confuse nullable types with optional parameters! While similar, optional parameters function differently than nullable types.

In Lua, omitted parameters are treated as nil, so leaving a blank space instead of writing nil for a nullable type will not throw an error.

Whichever you choose to do (explicitly write down nil vs. just leave it blank) is ultimately up to you. However, it is strongly advised that you explicitly write nil in place of a nullable parameter as to not confuse it with an optional parameter.

Attempting to run MyFunction(nil, nil) will throw an error (because requiredNumber is nil when it can't be), but running MyFunction(123, nil) will work fine, because nullableNumber is nullable, so it's safe for it to be nil.