Animating Text
Animating Text
Game UI can be significantly enhanced by outputting in-game text like NPC conversations, player instructions, and prompts with animated effects.
Animation Module
Animation effects can be bundled into a ModuleScript for convenient access from multiple text objects in your game.
- Create a new
ModuleScriptwithinReplicatedStorage. - Rename the new script AnimateUI.
- Paste the following code into the script:
If your game's source language is not English, change the
articles/localization portal additional features#locale-code-reference|locale code on line 4 (en) to match the game's source language setting in the localization portal.
Typewriter Effect
The “typewriter” effect is ideal for TextLabel|TextLabels that tell a story, output NPC conversations, etc.
- Create a
TextLabel(for testing, a suitable location is within aScreenGuiparented toStarterGui). - Insert a new
LocalScriptas a direct child of the label and paste in the following code. Note that each message is output by callingAnimateUI.typeWritewith parameters for the parent object, the string to output, and the delay between characters.
How it Works »
The module’s AnimateUI.typeWrite function works as follows:
- Initial setup occurs, including declaration of the
displayTextvariable equal to thetextparameter, and text translation if aTranslatorhas been loaded by the module’sAnimateUI.loadTranslatorfunction.
- If the text uses
articles/gui rich text|rich texttags, XML/HTML line breaks and other formatting characters are replaced, then the translated/modified text is set on the parent.
- The
displayTextstring is iterated over by UTF-8 grapheme clusters, increasing theTextLabel/MaxVisibleGraphemesproperty with a wait ofdelayBetweenCharsbetween characters.