Concatenation help

Hello, everyone!

I have four variables, that go message1, message2, message3 and message4.

I want to loop through these variables (which each contain a string) and put them on a TextLabel. Currently my script works fine, but I want to concatenate them so my code looks cleaner and I don’t have to have extra lines of code.

Here’s the script I had in mind:

for i = 1, 4 in pairs do
    TextLabel.Text = -- What would I put here?
    wait(4)
end

What should I use to concatenate this script? Thank you in advance.

You can instead put them in a table and do TextLabel.Text = table.concat(strings) where strings would be some table with your strings

Concatenation is the act of adding two strings together. I don’t think it will help you in this case. Your code is fine.

Oh, okay. I used the incorrect term, then. I’m sorry.

How would I represent these strings in a loop so that each time it loops, it will call a different variable using i?

-- So when it runs the script the x time then
for i = 1, 4 in pairs do
    TextLabel.Text = message(x)
    wait(4)
end
local strings = {"table", "of", "strings", "yay"}
for i = 1, 4 do
    TextLabel.Text = strings[i]
    wait(4)
end

Maybe this is the thing you are looking for?

“for i=1,4 in pairs do” is going to be an error.
You can either do

for i = 1, 4 do
    TextLabel.Text = strings[i]
    wait(4)
end

or

for i,v in pairs(strings) do
    TextLabel.Text = v
    wait(4)
end

Yeah, I didn’t realize xD, I just grabbed the code from previous dude and forgot to change that :smiley:

1 Like