Roblox GuidebookKnowledge base
English ⌄

Development / ROBLOX

Luau progress strings: keep the number behind the label

Build a clear progress message, convert a known numeric string deliberately, and avoid comparing displayed numbers as text.

Updated:

Start with a small delivery counter #

Imagine a practice delivery route with twenty parcels and a counter that currently reads seven. The important value is the number 7; the message shown to a player is a separate representation of that value. Decide which variable stores completed work and which expression creates the caption before adding any interface object. This separation makes the example easier to inspect.

The exercise uses fixed values selected by the author. It does not read player messages, award anything, or save progress. A console message can demonstrate string handling without claiming that a Roblox interface has been connected. Write the expected caption on paper first so that a successful run has a concrete meaning.

Create a caption without changing progress #

Run the first example in a Luau interpreter or a separate practice script. completed and total are numbers. tostring produces their textual representations; the two dots join the pieces. Spaces belong to the strings themselves, so the spaces around the slash are intentional. The first output should be Parcels: 7 / 20.

The second line uses string.format with %d placeholders for the same integer values. It should show exactly the same caption. Formatting changes the presentation, not completed. If you later increase completed numerically, build a fresh caption from the new value. Keeping an old caption in another variable will not automatically update it.

Number and captionOpen full-size image ↗
Original diagram: retain the number separately and create a caption from its current value.
local completed = 7
local total = 20
local caption = "Parcels: " .. tostring(completed) .. " / " .. tostring(total)
print(caption)
print(string.format("Parcels: %d / %d", completed, total))

Make spacing and wording explicit #

Concatenation does not invent a separator between neighbouring pieces. Joining the word Parcels and the number without a colon or a space creates a difficult label. Keep punctuation in one clearly visible template rather than spreading it among unrelated statements. Compare the complete output, including spaces, with the expected line.

Use integer placeholders only when your practice values are integers. A fraction needs a deliberate presentation rule instead of a promise that %d preserves every decimal. This lesson keeps the example at whole parcels. Changing the unit, showing a percentage, or rounding a value should be a conscious later decision with its own expected output.

Convert a known numeric string deliberately #

The second example begins with an author-chosen string, "7". tonumber attempts a numeric conversion, and a failed conversion returns nil. The explicit nil branch reports invalid progress and returns a fallback caption. A valid conversion creates the formatted caption. This makes the failure visible rather than silently pretending that invalid text means zero.

The example also receives "seven" as a negative case. Its two output lines are Invalid progress and Parcels: unavailable. A conversion is not a complete game rule: numeric values still need checks for the allowed range and integer requirement if a later system accepts them. No player-controlled input or displayed chat text is part of this exercise.

Conversion checkOpen full-size image ↗
Original conversion diagram: nil takes an explicit failure branch.
local function progressCaption(raw)
    local completed = tonumber(raw)
    if completed == nil then
        print("Invalid progress")
        return "Parcels: unavailable"
    end
    return string.format("Parcels: %d / %d", completed, 20)
end
print(progressCaption("7"))
print(progressCaption("seven"))

Do not order progress labels as numbers #

Compare "100" and "20" as strings and you are asking for textual ordering, not numerical magnitude. The leading character can determine the result before the remaining digits matter. In this practice case, the string comparison returns true even though the number 100 is greater than the number 20. That mismatch is a useful warning sign.

For a numerical comparison, keep both quantities numeric, or convert known strings and handle nil before comparing. Do not repair the problem by padding the visible label with zeros unless fixed-width textual ordering is genuinely the intended design. A display convention should not become the source of truth for completed work.

Check conversion and game constraints separately #

Successful conversion answers whether text can be interpreted as a number. It does not answer whether that number is a suitable parcel count. A negative quantity, a fraction, or a value above total might be numeric and still violate the intended rule. Describe those decisions before building the production check.

Our demonstration intentionally tests only a valid numeric string and a clearly invalid word. The executable assertions also confirm the distinction between text and number ordering. They do not certify every possible input, every locale, or a live Roblox game. State that limited scope in the handoff so another developer can add the missing domain checks.

Translate the caption while keeping the data stable #

A translated explanation may describe the caption in another language, but the code examples retain their fixed English output so that every reader can run the same comparison. In a real localized interface, place wording and punctuation in an appropriate translated template. Keep the numeric meaning independent of that template.

Check a longer translation and a right-to-left layout separately when you later connect an actual interface. This article does not demonstrate that connection or prove that any text fits on a phone. The useful transfer is the data boundary: a number is used for calculation, while a localized string is created for reading.

InputExpected output
Numbers 7 and 20Parcels: 7 / 20
String 7Parcels: 7 / 20
Word sevenError and fallback caption
Strings 100 and 20Text comparison returns true

Hand off a reproducible result #

Save the two source examples, the expected output, and the assertion file together. Record which interpreter ran them and whether it completed successfully. A colleague should be able to recreate the caption and the invalid branch without needing an account, a server, or access to your published game.

Before extending the exercise, ask whether calculations still use numbers, whether missing conversions take an explicit branch, and whether the full caption includes the intended separators. Then specify the next real integration step separately. A clean console result is evidence for these string operations; it is not evidence that progress has been saved or shown to players.

RecordWhat to hand off
DataNumeric completed and total
CaptionTemplate and complete output
Failurenil branch and fallback text
VerificationInterpreter and actual output

Original sources

Roblox — Official documentation