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

How to add a digit to text value? dont do math SOLVED

Asked by
ErtyPL 129
5 years ago
Edited 3 years ago

I want to add a digit to a textbox/stringvalue. I mean I don't want to do math like 1+1=2 but just get the current number like 1 and add to it 1 so the script would change text value to 11 (Yes, I didn't know the concatenation)

01script.Parent.MouseButton1Click:connect(function(buy)
02local view = script.Parent.Parent.Parent.SUMA.P12.Text
03 
04    if view == 0 then
05    wait(1) -- just nothing
06    elseif view > 0 then
07    -- there i need that function so to add a digit in text
08 
09    wait(1)
10    end
11 
12end)

Well, I'm new to Lua programming.

2 answers

Log in to vote
4
Answered by
oreoollie 649 Moderation Voter
5 years ago
Edited 5 years ago

What you're trying to do is called concatenation. The concatenation operator in Lua is .. here's an example of its use:

1local str = "Concat"
2 
3print(str .. "enation") -- Prints "Concatenation"

If my answer solved your problem please don't forget to upvote and accept it!

Ad
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

You could do x * 10 + y, this would effectively add a digit to your value.

1function addDigit(x,y)
2    return x * 10 + y
3end
4print(addDigit(5,7))
5 
6print(addDigit(234,8))

Output:

57

2348

2
this would not work for 0 User#5423 17 — 5y

Answer this question