Skip to content

useCountdown

Lucy.useCountdown counts whole seconds left until endsAt using workspace:GetServerTimeNow(). Because every client reads server time, all players see the same second tick down without the server sending updates every second.

Usage

useCountdown exampleuseCountdown example
local timer = Lucy.useCountdown(setEndsAt)

Lucy.Text.new({
    text = function()
        return `{timer.remaining()}s left in the set`
    end,
})
ArgumentTypeDefaultWhat it is
endsAtMaybeRef<number?>requiredTarget timestamp in workspace:GetServerTimeNow() seconds

Returns

NameTypeWhat it is
remaining()() -> numberWhole seconds left until endsAt, never below 0. Updates once per second
done()() -> booleantrue once remaining() reaches 0

If endsAt is nil, remaining is 0 and done is false. When the target timestamp changes, the countdown adjusts immediately.

Example: Club Lucy DJ set round timer

Show how long remains in DJ Lucy’s current set:

local currentSetEndsAt = app.state:ref("booth.roundEndsAt")
local countdown = Lucy.useCountdown(currentSetEndsAt)

Lucy.Text.new({
    text = function()
        if countdown.done() then
            return "Set finished! Next DJ up..."
        end
        return `{countdown.remaining()} seconds remaining in set`
    end,
    Parent = hud,
})