Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I add another text in string.sub?

Asked by 4 years ago
Edited 4 years ago

When I try

01local texts ={
02"TestMessage 1",
03"TestMessage 2"
04}
05 
06wait(8)
07for i = 1,#texts do
08    script.Parent.Text = string.sub(texts,1,i)
09    wait(0.1)
10end

it won't work while it work before I added the second one.

1local text = "test message"
2 
3wait(8)
4for i = 1,#text do
5    script.Parent.Text = string.sub(text,1,i)
6    wait(0.1)
7end

Is there any way to fix?

1 answer

Log in to vote
1
Answered by 4 years ago

Firstly, I noticed you we're using an Array of Text Strings so before, we can do anything. We will need to require those messages by using a simple method:

1for i,v in pairs(Sayings) do -- Gathering all the Messages typed in the Array.

We will also need to determine how fast the message is typed by using:

1for i = 1, #v.Text do -- Determines Typed Amount.

Now, we can begin on the UI stuff and making the message type out. We can achieve this by using:

1script.Parent.Text = string.sub(v.Text, 1, i) -- Type the Message Out
2wait(0) -- This will determine the speed of the text, you can change this to whatever you want.

That is all that sorted and your final code should look like this:

01local UI = script.Parent
02local debounce = false
03local Sayings = {
04{Text = "Hello, I am a test message 1"},
05{Text = "Hello, I am a test message 2"},
06{Text = "Hello, I am a test message 3"},
07}
08 
09wait(5) -- Wait before Starting
10for i,v in pairs(Sayings) do -- Gathering all the Messages typed in the Array.
11wait(3) -- How long to Wait Before Messages
12for i = 1, #v.Text do -- Determines Typed Amount.
13script.Parent.Text = string.sub(v.Text, 1, i) -- Type the Message Out
14wait(0) -- This will determine the speed of the text, you can change this to whatever you want.
15end
16end

I hope this helped you out.

Ad

Answer this question