Number Field
A number in a field, with a minus button before it and a plus button after it, for counts and amounts: dancers in a party, a track’s BPM, emotes to buy. Press the buttons, or hold them to keep going faster, or type a number. On keyboard and gamepad the field is one stop: left and right change the number, like a slider, and the confirm button starts typing.


Lucy.Stack.new({
direction = "horizontal",
gap = "Space4",
align = "center",
children = {
Lucy.Text.new({ text = "Party size", variant = "large", autoWidth = true }),
Lucy.NumberField.new({
value = 4,
min = 1,
max = 16,
width = UDim.new(0, 160),
onValueCommit = function(dancers)
app.toast(`Room for {dancers} dancers`)
end,
}),
},
Parent = parent,
})
Props
| Prop | Type | Default | State key | What it does |
|---|---|---|---|---|
value | number | 0 | yes | The current number |
min | number | no limit | yes | The lowest number |
max | number | no limit | yes | The highest number |
step | number | 1 | yes | How much the buttons and arrows change it; typed numbers snap to it |
placeholder | string | "" | yes | Grey text shown while the field is empty |
disabled | boolean | false | yes | Greys it out and ignores input |
visible | boolean | true | yes | Shows or hides it |
format | function | Turns the number into the shown text; whole numbers have no point by default | ||
width | UDim | fills the parent | How wide the whole field is, buttons included | |
onValueChange | function | Called with (value, handle) on every change, while a button is held too | ||
onValueCommit | function | Called with (value, handle) once per press, held arrow or typed number that changed it |
It also takes the props every component takes.
A typed number counts when the player presses Enter or leaves the field. It is snapped to the step and kept between min and max; anything that is not a number puts the old value back. Steps count from min when there is one, from zero when not. Values are cleaned up after each step, so 0.1 steps give 0.3, not 0.30000000000000004. A button turns grey at the end it moves towards.
The buttons draw the lucy:minus and lucy:plus icons. To use your own, see Icons Lucy draws.
Methods
| Name | What it does |
|---|---|
field:setValue(value) | Sets the number, snapped to the step and kept in range |
Examples
Keep the Booth’s BPM in app state and save it once the player has picked:


local bpm = app.state:ref("booth.bpm")
Lucy.NumberField.new({
value = bpm,
min = 60,
max = 180,
onValueCommit = function(value)
remotes.SaveSetting:FireServer("bpm", value)
end,
Parent = booth,
})
A track’s playback speed in quarter steps, shown with a suffix:


Lucy.NumberField.new({
value = 1,
min = 0.25,
max = 4,
step = 0.25,
width = UDim.new(0, 200),
format = function(value)
return string.format("%.2fx", value)
end,
Parent = booth,
})
Preview
In Studio, from the command bar: Lucy.Preview.show("NumberField").