local Test = game.StarterGui.Gui.TextBox
Test.Text = "H"
Test.Text = "He"
Test.Text = "Hel"
Test.Text = "Hello"
Im trying to make this thing where the text gradually appears. The only way i know how to do it is listed above. Is there any method to shorten it?
Sure, so let me introduce you to the string global! The one we’ll be focusing on right now is string.sub(). string.sub() can return the substring of s that starts at i and continues until j. So, taking this knowledge and for i loops, we can simply do this.
local function TextEffect(Text)
for i = 1,#Text, 1 do -- // This starts at 1 and ends at the amount of characters in Text.
local subbedString = string.sub(Text,1,i) -- // Starts at the first character and gradually increases i,
--hence showing more of the string
Test.Text = subbedString
I suggest adding a
wait() in there, as I think @ChickHenEn wants to make a typewriter.
Oh yeah my bad, totally slipped my mind, thanks.
If you’re creating a typewriter effect, you could try changing the MaxVisibleGraphemes property of the textlabel instead. Test.Text = “Hello” with MaxVisibleGraphemes set to 1 will read “H”, and you can tween/loop increment that value until you reach the size of the string.