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 2 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)

script.Parent.MouseButton1Click:connect(function(buy)
local view = script.Parent.Parent.Parent.SUMA.P12.Text

    if view == 0 then
    wait(1) -- just nothing
    elseif view > 0 then 
    -- there i need that function so to add a digit in text

    wait(1)
    end

end)

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:

local str = "Concat"

print(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.

function addDigit(x,y)
    return x * 10 + y
end
print(addDigit(5,7))

print(addDigit(234,8))

Output:

57

2348

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

Answer this question