Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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!

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

1 comment

2

this would not work for 0

This discussion is preserved as it was. New answers, comments, and votes are closed.