Ad
Log in to vote
0

How do I add another text in string.sub?

Asked by 2 years ago
Edited 2 years ago

When I try

local texts ={
"TestMessage 1",
"TestMessage 2"
}

wait(8)
for i = 1,#texts do
    script.Parent.Text = string.sub(texts,1,i)
    wait(0.1)
end

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

local text = "test message"

wait(8)
for i = 1,#text do
    script.Parent.Text = string.sub(text,1,i)
    wait(0.1)
end

Is there any way to fix?

1 answer

Log in to vote
1
Answered by 2 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:

for 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:

for 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:

script.Parent.Text = string.sub(v.Text, 1, i) -- Type the Message Out
wait(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:

local UI = script.Parent
local debounce = false
local Sayings = {
{Text = "Hello, I am a test message 1"},
{Text = "Hello, I am a test message 2"},
{Text = "Hello, I am a test message 3"},
}

wait(5) -- Wait before Starting
for i,v in pairs(Sayings) do -- Gathering all the Messages typed in the Array.
wait(3) -- How long to Wait Before Messages
for i = 1, #v.Text do -- Determines Typed Amount.
script.Parent.Text = string.sub(v.Text, 1, i) -- Type the Message Out
wait(0) -- This will determine the speed of the text, you can change this to whatever you want.
end
end

I hope this helped you out.

Ad

Answer this question