Skip to content

Utils

Plain helpers and utility classes that work anywhere on the client or server, without components or reactive scopes.

UtilityWhat it does
Lucy.FormatFormats numbers with thousands separators and decimal rounding
Lucy.ScrollScrolls ancestor ScrollingFrames to show an object and reads combined UIScale
Lucy.SignalSynchronous event emitter for plain Luau objects
Lucy.MaidCollects instances, connections, functions and threads to clean them up in one call

Lucy.Format

Lucy.Format turns values into strings, with nothing to set up or clean up.

Format.number

Lucy.Format.number(4200)             -- "4,200"
Lucy.Format.number(-1500)            -- "-1,500"
Lucy.Format.number(1234.5678, 2)     -- "1,234.57"
Lucy.Format.number(1234567, 0, ".")  -- "1.234.567"

Groups thousands and rounds to decimals places.

ArgumentTypeDefaultWhat it does
nnumberrequiredNumber to format
decimalsnumber?0Decimal places to round to
separatorstring?","Separator between groups of three digits

Luau’s string.format pads and rounds ("%.1f", "%05d"), without adding thousands separators.

Formatting labels in UI

Format numbers inside labels and counters:

local coins = app.state:ref("player.coins")

Lucy.Text.new({
    text = function()
        return `{Lucy.Format.number(coins())} coins`
    end,
    Parent = hud,
})

A Text with a numeric value formats numbers with Lucy.Format.number by default, and useCount follows the same formatting.

Lucy.Scroll

Lucy.Scroll provides helpers for ScrollingFrames. InputManager uses it to keep focused items in view on keyboard and gamepad, and you can call it directly in your own menus.

Scroll.reveal

Scrolls every ScrollingFrame ancestor above object until object fits inside each viewport, or only the single frame you pass in only:

Lucy.Scroll.reveal(object, margin?, only?)
ArgumentTypeDefaultWhat it does
objectGuiObjectrequiredElement to scroll into view
marginnumber?8Extra padding in pixels around object
onlyScrollingFrame?every ancestorScroll only this frame and leave outer scrollers alone

When that leaves it within a quarter of a view of the start or the end of the canvas, it scrolls all the way there. So when a controller comes back up to the first control, the heading above it comes into view as well, and the same for what sits under the last control.

Pass only when one scroller sits inside another: a tab bar scrolls its active tab into view inside its own strip without scrolling the whole page.

CanvasPosition, AbsolutePosition and AbsoluteWindowSize are measured in screen pixels (after UIScale), so reveal works across densities without extra maths.

-- Jump to a picked track in the booth queue
local function highlightTrack(trackItem: GuiObject)
    Lucy.Scroll.reveal(trackItem, 16)
end

Scroll.offsetFor

Computes the new canvas offset along one axis needed to bring a span into view:

local newOffset = Lucy.Scroll.offsetFor(position, view, top, bottom, margin?, extent?)
ArgumentTypeDefaultWhat it does
positionnumberrequiredCurrent canvas scroll position
viewnumberrequiredVisible window size along the axis
topnumberrequiredStart of the span in canvas space
bottomnumberrequiredEnd of the span in canvas space
marginnumber?0Extra padding around the span
extentnumber?noneThe canvas’s length. With it, an offset that would stop within a quarter of a view of the start or the end goes all the way there

Returns position unchanged when the span is already in view. When the span is taller than view, it aligns the top edge.

Scroll.whenNear

Calls a function once, the first time an object is shown and near what the scroll area around it shows. It returns a function that stops it looking:

local stop = Lucy.Scroll.whenNear(object, callback, overscan?)
ArgumentTypeDefaultWhat it does
objectGuiObjectrequiredWhat to watch. It needs a size of its own
callback() -> ()requiredCalled once, then it stops looking
overscannumber?1How many views beyond each edge of the visible part count as near

Shown means the object and everything above it is visible, in a gui that is on. With no scroll area around the object, it calls back as soon as the object shows. In a component or a scene, use useIntersect, which stops with its owner; a Stack does it for its children.

Scroll.scaleOf

Returns the combined scale factor of every UIScale above object:

local scale = Lucy.Scroll.scaleOf(object)

Use scaleOf to convert measured screen pixels (AbsoluteSize) back into unscaled layout offsets for UDim2.

Lucy.Signal

Lucy.Signal is a synchronous event for plain Luau objects when a Roblox RBXScriptSignal is not available. Handlers run in connection order; an error in one logs a warning and does not stop the rest.

Methods

MethodReturnsWhat it does
Signal.new()SignalCreates a signal
signal:Connect(fn)ConnectionRegisters a handler
signal:Once(fn)ConnectionRegisters a handler that disconnects after firing once
signal:Fire(...)()Calls every active handler synchronously with the arguments
signal:DisconnectAll()()Disconnects all active handlers

A Connection provides conn.Connected (boolean) and conn:Disconnect().

Example: booth events

Use signals for plain Luau events between game systems and UI:

local onTrackChanged = Lucy.Signal.new()

local conn = onTrackChanged:Connect(function(trackName: string, bpm: number)
    print(`Now playing {trackName} at {bpm} BPM`)
end)

onTrackChanged:Fire("Neon Nights", 124)

conn:Disconnect()

Lucy.Maid

Lucy.Maid collects cleanup tasks and tears them down together in reverse order (last in, first out), so later resources clean up before the things they depend on.

Supported cleanup types

TypeHow Maid cleans it
InstanceCalls item:Destroy()
RBXScriptConnectionCalls item:Disconnect()
Lucy.Signal.ConnectionCalls item:Disconnect()
functionCalls item()
threadCancels via task.cancel(thread) if still alive
tableCalls item:Destroy(), item:destroy(), or item:Disconnect()

Methods

MethodWhat it does
Maid.new()Creates an empty Maid
maid:give(item)Adds item to the cleanup list and returns it
maid:clean()Cleans every item in reverse order and clears the list
maid:destroy()Alias for maid:clean()
maid:Destroy()Alias for maid:clean()

Example: cleaning up floor effects

local floorMaid = Lucy.Maid.new()

floorMaid:give(danceFloorLightPart)
floorMaid:give(sound.Ended:Connect(onTrackFinished))
floorMaid:give(task.spawn(pulseFloorBeats))
floorMaid:give(function()
    print("Dance floor effects torn down")
end)

-- When the player leaves the floor, clean everything in one call:
floorMaid:clean()