schema.boolean
function#Accepts a boolean.
local flag = schema.boolean()Use it forstoring a true or false answer, like whether a player owns a pass or has finished the tutorial.
Check the shape of values
local schema = require("@usbx/schema")Accepts a boolean.
local flag = schema.boolean()Use it forstoring a true or false answer, like whether a player owns a pass or has finished the tutorial.
Accepts a number.
local level = schema.number({ min = 1, integer = true })Use it forstoring tokens, levels or health, with a lowest and highest value if you want one.
optionsoptionalLimits on the number.number callmin · max · integerminThe lowest number the value is allowed to be.
maxThe highest number the value is allowed to be.
integerSet it to true to allow only whole numbers, so values with a decimal part are not accepted.
Accepts a string.
local nickname = schema.string({ max_length = 20 })Use it forstoring a nickname or pet name, and keeping it under a length limit you choose.
optionsoptionalLimits on the text.string callmax_lengthmax_lengthThe most characters the text is allowed to have.
Accepts a vector.
local spot = schema.vector3()Use it forstoring a position, like a player's last checkpoint or where something should spawn.
Accepts a color.
local tint = schema.color()Use it forstoring a color a player picked, like the paint on their car or their outfit.
Accepts an instance.
local target = schema.instance({ kind = "part" })Use it forstoring which part or other instance is the current target or goal of a round.
optionsoptionalWhich kind of instance.instance callkindkindAccepts only instances of this kind, so you give a kind name written the same way as the examples.
Accepts a player.
local owner = schema.player()Use it forstoring who is "it" in a game of tag, or which player owns a shop.
Also accepts nil.
local title = schema.optional(schema.string())Use it forstoring something a player might not have yet, like a title, which stays nil until they earn it.
schemaWhat a value that is not nil must fit.Accepts a list.
local names = schema.array(schema.string())Use it forstoring a list, like a player's inventory or the badges they have collected so far.
schemaWhat every item must fit.Accepts a table with these fields. Luau cannot work out its type: name it, as in Schema<{ level: number }>.
local stats: Schema<{ name: string, level: number }> = schema.struct({ name = schema.string(), level = schema.number({ min = 1 }) })Use it forstoring several named values together, like a player's saved name, level and XP.
fieldsThe schema of each field, by name.Accepts one of these strings. Luau cannot work out its type: name it, as in Schema<"easy" | "hard">.
local mode: Schema<"easy" | "hard"> = schema.enum({ "easy", "hard" })Use it forstoring a choice from a fixed list of words, like a difficulty or a game mode.
valuesThe strings it accepts.Accepts a table whose keys and values fit the schemas.
local scores = schema.map(schema.string(), schema.number())Use it forstoring scores by player name, or how many of each item a player has by item name.
keysWhat every key must fit.valuesWhat every value must fit.Accepts a value that fits one of two or more schemas. Luau cannot work out its type: name it, as in Schema<string | number>.
local id = schema.union(schema.string(), schema.number())Use it forstoring a value that can fit more than one schema, like an ID that is text or a number.
...optionalTwo or more schemas.Accepts any value, also nil.
local anything = schema.any()Use it forstoring a value of any shape, with no checking.