2 Method's for Typewriter Effect's

Hi, This is kind of a Small Tutorial to show you how to make a Simple Typewriting Effect

This isn’t really Advanced, But more of Basic and Simple way of doing it, but still can be useful to know.

(Please Note that this is just my way of doing this, sorry if I'm a bit confusing on some parts)


Put this script is inside:

  • StarterGui (I dont recommend this always as it doesnt work half the time)

  • ServerScriptService


It can be any Script:

  • A Standard Script

  • A LocalScript


MaxVisibleGraphemes Version
  1. Assign a Variable to your TextLabel or TextButton
    This is just so you can get the Text Part, Kind of Important
local TextLabel = script.Parent.ScreenGui:WaitForChild("TextLabel")
  1. Create a function!
    Create a function and Assign a Argument as a string , Doing this will make the function look for a string and not anything else, if there is another type, it will error :confused:
local function TypeWrite(str: string) -- "str" is assigned as a String
-- Will Come in...
end
  1. Apply Text and MaxVisibleGraphemes
    We make sure to set the text to the string we write, if we dont, it will just typewrite was is already there.
    Inside your TextLabel, Set MaxVisibleGraphemes to 0, what this will do is make the Characters Disappear, For Example: adding a number like 1, will make one Character Appear,
local function TypeWrite(str: string)
TextLabel.MaxVisibleGraphemes = 0 -- Makes 0 Characters Visible
TextLabel.Text = str -- Sets the Text to the String we wrote
end
  1. String Length
    Get the Length of the String! Obviously we don’t have a string at the moment but still, this is important to know how big our String is, Lets way our String is Hi, There is only 2 Characters inside so its Length is 2, You can get the Length of the String by using :len()

Example:

local Str = "Hi" -- "Hi" is our string
print(Str:len()) -- Will Print "2"

As For our code, We will Create a For Loop, Since our String Length is 2, We can create a loop so it fires for the length of the string (so 2 Times),
Please NEVER forget to add a wait inside a loop, it will Crash your game!

local function TypeWrite(str: string)
TextLabel.MaxVisibleGraphemes = 0
TextLabel.Text = str

for i = 1,str:len() do -- Since the Length of our string is a Number, Will Determine how many times it will run
task.wait(.1) -- Waits for 0.1 Seconds (1/10)
-- More in a sec...
end
end
  1. Add Graphemes!
    Add the Graphemes inside the Loop, we do this because it will make the Characters Visible, and since the Length of Hi is 2, It will fire two times to form the Word Hi, This Should be the finished code:
local TextLabel = script.Parent.ScreenGui:WaitForChild("TextLabel")

local function TypeWrite(str: string)
TextLabel.MaxVisibleGraphemes = 0
TextLabel.Text = str

for i = 1,str:len() do
task.wait(.1)
TextLabel.MaxVisibleGraphemes += 1 -- Adds Graphemes (Visible Characters)
end
end

And Finally…

  1. Test the Code!
    If you test it now, you may notice that its not firing, thats because we havent called it yet, to do this we write the name of the function (Which in the Script is TypeWrite) and add Parenthesis (), and since the function is also looking for a string, we add one inside of it:
TypeWrite("OMG This is a Typewriting Effect!") -- String Inside the Parenthesis, otherwise it will error

Now Test it, and it should work as intended!
(Note in this Clip, i added sound and made the Speed Faster)

string.sub Version (Slightly more Advanced)

If MaxVisibleGraphemes Doesn’t get you the result you like, try using string.sub, This is slightly more complicated, but i will go over the same steps as the Other Example:

I recommend Reading This to understand a little better.

  1. Assign a Variable to your TextLabel or TextButton
    This is just so you can get the Text Part, Kind of Important
local TextLabel = script.Parent.ScreenGui:WaitForChild("TextLabel")
  1. Create a function!
    Create a function and Assign a Argument as a string , Doing this will make the function look for a string and not anything else, if there is another type, it will error :confused:
local function TypeWrite(str: string) -- "str" is assigned as a String
-- Will Come in yet again...
end
  1. Length
    To Get the Length of the String, you can use :len() for this, we will Apply a for loop, since the length of the String is a number, it will determine how many times it will run.
    Once Again
    NEVER forget the wait inside the Loop, it will crash your game!
local function TypeWrite(str: string)
   for i = 1,str:len() do -- Length is a number, Determines how many times it will run
      task.wait(.1)
      -- More in a sec..
   end
end
  1. Apply Text with string.sub
    string.sub can be a bit confusing to use, hopefully this Post can help you out with that
  • s: string is our String
  • i: number is the Number our string start’s at
    lets say you have a string named carl, if we start at 2, the string will be arl since we took away the first two letters, I will show how to fix to make it say ca later (Default is 1)
  • j: number is our Target, This integer is optional but will be very useful here (Default is -1)

As I said I would, to change the arl to ca we would do this:

local s = "carl"

print(string.sub(s,1, 2)) -- will print "ca"

For Better Explaination

We are setting i to 1 with is the Default Value (gives us the first letter),
while j is the Targetted value so if it was 1, then it will only print c, but since its 2, it will also print a which gives the result of ca

As for our for loop, we will assign j as the index

local function TypeWrite(str: string)
   for i = 1,str:len() do
      task.wait(.1)
      TextLabel.Text = string.sub(str,1,i) -- It will add the Text instead of Subtracting it, And our Target is the string's length
   end
end
  1. Test The Code:
    To test the code, we do the same thing as the first Tutorial, Call the function
TypeWrite("OMG This is a Typewriting Effect!") 

After this, it should work wonderfully :slight_smile:


What Do you think?
  • Very Useful
  • Good
  • Ok
  • Bad
  • Not Helpful

0 voters


Hidden Because Yes
Stop It
Please, No
I'm Warning You!
You Just Don't Give Up Do you?
STOP
AAAAAAAAAAAAAAUUUUUUUUGGGGGH
You Know what, FINE, HERE
YOU THOUGHT
NONONONONONONO

Eggs

Also Hidden because Yes
Stop!
Please
No
No.
No!
NO!
weiufjogkerogierkgeroig

Secret To Life

13 Likes

This is a pretty good tutorial! Although for this part,

You can also use

#Str

But they both work the same.

6 Likes

Yeah, I know that, but I’d rather use the function just to make it a bit easier to understand :face_with_diagonal_mouth:

2 Likes

This is useful. Never knew there was a property that does that!

2 Likes

(Sorry, accidentally replied to you.)

Spoiler for the last part of the dropdown

image

But yeah, it’s a neat tutorial, at least, better understanding than the Roblox guide version.

1 Like

Hey Thanks, didn’t know i was better at explaining things


(nooo, the secret)
Off Topic
The Real Question is what’s in the Link?

1 Like
1 Like

@SuperDeusterMan @AridTheDev
I made some Updates, I have now included a string.sub version, however at the cost of the poll.

I like the tutorial but I hate the part at the end of the post.

true

Summary

Yes

1 Like

Using string.sub to do typewriter effects should never be used because you can’t translate text when using it

1 Like

It really depends,
Using string.sub() is better with the look’s of your UI, but not the languages,

You can probably translate the string before using string.sub

Using MaxVisibleGraphemes can be ugly depending if you position the Text Correctly, but it can be translated.

1 Like

Another one using game:GetService(“TextService”):GetTextSize and multiple textlabels. You can animate each letter individually. Likely the most advanced though. Took me 4 tries to make it work (like completely rewritten)

2 Likes

I see.

Summary

Noted…
Yes…

Very sneaky Rick Roll

This looks great! Might consider using this for a game soon!

I was waiting for it lol

Yes, but string.sub doesn’t take into account things that span over multiple characters, like :+1:t6:, since it combines 2 characters, the thumbs up emoji and a dark skin modifier.

To be fair, you didn’t listen

E