I made a way to make NPC type that actually works, but to make it talk, I paste it as much times as the number of characters in the sentence, and then make it so after 0.05 seconds it types another character. Is there a faster way instead of removing a character from the text every time? (This is a LocalScript, so it can work with filteringenabled.)
01 | function onClick 3 (plr) |
02 | local text = plr.PlayerGui.TalkGui.Message 3. TextLabel |
03 | text.Parent:TweenPosition(UDim 2. new( 0.3 , 0 , 0.623 , 0 ), 'Out' , 'Quad' , 0.23 ) -- gui pops up |
04 | wait( 0.25 ) |
05 | sound:Play() -- talking sound plays |
06 | text.Text = "" |
07 | wait( 0.05 ) |
08 | text.Text = "D" |
09 | wait( 0.05 ) |
10 | text.Text = "Do " |
11 | wait( 0.05 ) |
12 | text.Text = "Do y" |
13 | wait( 0.05 ) |
14 | text.Text = "Do yo" |
15 | wait( 0.05 ) |
string.sub
is what you'll need. string.sub(text, start, end)
will return the part of the string from the start
to end
, or from the start
to the end of the string - if the end
parameter isn't specified.
1 | local txt = 'Do you like being classy?' |
2 |
3 | for i = 1 , #txt do |
4 | text.Text = txt:sub( 1 , i) |
5 | wait() |
6 | end |
P.S: txt:sub(1, i) is syntactic sugar for string.sub(txt, 1, i)