pesde goatsoft / lucy

useReveal

Lucy.useReveal reveals a string a character at a time and returns a visible count you can bind straight to a TextLabel's MaxVisibleGraphemes.

Because MaxVisibleGraphemes hides later letters without changing the string, Roblox lays out the full text on frame one so words do not jump onto new lines as they appear.

Usage

local typed = Lucy.useReveal(text, options?)
ArgumentTypeDefaultWhat it is
textMaybeRef<string>requiredText to reveal
optionstable?{}Rate and rich text options

Options

OptionTypeDefaultWhat it does
ratenumber40Characters shown per second
richbooleanfalseSkips rich text tags (<b>, <font>) instead of counting them

Returns

NameTypeWhat it is
visible()() -> numberNumber of characters to show (-1 once finished)
revealing()() -> booleantrue while typing
skip()() -> ()Shows the rest of the text at once
doneLucy.SignalFires when the text finishes revealing

Example: DJ dialogue

Type out DJ Lucy's spoken line with a button to skip or move on:

local speech = app.state:ref("npc.dialogue")
local typed = Lucy.useReveal(speech, { rate = 32, rich = true })

local label = Lucy.new "TextLabel" {
    Text = speech,
    RichText = true,
    MaxVisibleGraphemes = typed.visible,
    Parent = dialogueBox,
}

local skipOrNextButton = Lucy.Button.new({
    text = function()
        return if typed.revealing() then "Skip" else "Next"
    end,
    onClick = function()
        if typed.revealing() then
            typed.skip()
        else
            advanceDialogue()
        end
    end,
    Parent = dialogueBox,
})

Text has this built in via reveal: Lucy.Text.new({ text = line, reveal = 32 }).