How do i add 2 variables together?

How could i add two variables together?
Here is an example of what i mean:
Variable1 + Variable2 or something like that.

Any help would be appreciated.

1 Like
local Add1 = 50
local Add2 = 25

local Result = Add1 + Add2
print(Result)

Just make sure they’re numbered values

local Result = Value 1 + Value 2

What is suppose to be in the variable. An Object? A number? A text? :thinking:

It should just be anything relevant to a numeric number, as long as the variable is equal to some number (40, 50, etc)

1 Like

yes if the variable is a number or a string aka a text it is possible to add them up. But I need to know exactly what is he planning on using this on. :smiley:

Text, im trying to add two values of text together for a banned player webhook

So, you could do this for example

print(Variable1.. Variable2)

This would mean that it comes out as one.

So what you could also do is:

local Variable3 = Variable..Variable2

Resulting in them being combined.

1 Like

You can also use string.format if you need to concatenate (add two things together, such as strings) multiple strings and variables. It also supports some other useful features (refer to article linked below)

-- e.g. instead of:
local text = user .. "has been banned by " .. admin .. " on " .. banDate .. "."

-- you can do this:
local text = string.format("%s has been banned by %s on %s.", user, admin, banDate)

2 Likes

Do you mean something such as:

local Variable, Variable2

?

This is probably what you’re talking about???

local str1 = "Hi"
local str2 = "Test"

print(str1..str2) -- "Hi Test"

(its called concatenating btw)

1 Like

None of these have really worked for my webhook system, i think it might be an error on my side with the code i made for it.

But thanks for the help, Ill try to see why it wont work

Can u show me some of your script? Then it’s easyer to understand what u really mean

It could be possible that you needed a space in between the two strings but forgot one. An example:

local Str1 = "Hi"
local Str2 = "how are you?"

print(Str1..Str2)
-- The print will return "Hihow are you?" in the output.

print(Str1..""..Str2)
-- The empty quotation I added acts as a "space" and now the output will be Hi how are you?

Then again, this is just a possibility. If it still doesn’t work, let me know!

4 Likes