How to add to string?

I’m attempting to add a piece of string to itself.

Example: Word “Potato” I want to add a letter (a-z) on it every time I run the script,

Ex: Potatos, Potatosz, Potatosse

Does anyone know any easy solutions to this?

I’m currently having a hard time finding out how to do this, I’ve checked through the wiki’s but can’t seem to find a solution.

Apologies if this seems informal, quite new to posting on devforums.

EDIT: Looking for a way to add letters specifically to a stringvalue,

example: I want to add a letter a to the current string value.

Original String value: Potato
Run of script: Potatoa
2nd Run of script: Potatoaa

What im currently trying right now is
script.Parent.Parent.Parent.FIRSTVARIABLE.Value = (script.Parent.Parent.Parent.FIRSTVARIABLE … “1”)

Use .. at the end of a string followed by the string you want to append.
E.g.

print("Hello" .. "World")
8 Likes

Apologies for me not being clear or for me not understanding, I’m looking for a way to repeat the addition of strings such as values

EX: Value = (Value + 1)

1 Like

You could use:
String = String .. " lol"

misunderstood the OP

so you want to run a for loop that iterates through a list of the alphabet, right?

Hmm, welcome to the DevForum. Not sure what you meant but the person above just shows you the way to what we would call combining strings, or string concatenation and that’s one of the steps.

If we take a look at it, you need to define a variable for your default word, it would be.

local originalWord = "Potato"
local otherWord = "Apple"

print(originalWord..otherWord)

PotatoApple

To repeat, you can use a loop.

2 Likes

Hey slothful guy, My question is though, if I ran the loop three times over, would the print be

PotatoAppleAppleApple?

in that case you would do

local alphabet = {"a", "b", "c"} --etc
local mystring = "Hello World!"
local function addletter ()
    mystring = mystring .. alphabet[math.random(1, #alphabet)]
end

like sloth said, this is called string concatenation under the umbrella term of string manipulation. it’s an important skill and you should try to be well-versed in it.

5 Likes


Apologies, but I should’ve been more clearer, I’m looking for a way to add letters to a "StringValue"

you have to add it to the string value’s value
so reference StringValue.Value

5 Likes