I’m making a key pad when I came across this issue. I can’t add the inputted numbers because if I did 5 and 6, instead of 56, I get 11. I am able to get the inputted numbers thankfully.
Number123 is the inputted number, currentCode is the total numbers, and canPress is if the player can click on any numbers.
Instead of using the addition arithmetic operator use the concatenation operator.
local currentCode = number1 .. number2 .. number3 .. number4
Something like that ^
1 Like
You are adding numbers, instead what you want to do is concatenate strings.
Concatenation is a fancy word for joining two strings together.
Addition
print(1 + 1 + 1 + 1) --> 4
Concatenation
print("1".. "1".. "1".. "1") --> "1111"
In your case that would be…
local KeypadDigits = ""
local CorrectPIN = "1234"
local function EnterDigit(digit: string)
KeypadDigits ..= digit -- Concatenate all the previously entered digits with newly entered digit
if KeypadDigits == CorrectPIN then -- Do they match up?
print("Unlocked") -- Yes, they do match up, print "Unlocked" for debugging purposes
end
end
-- Example usage
EnterDigit("1")
EnterDigit("2")
EnterDigit("3")
EnterDigit("4")
So whenever player presses a button on a keypad input, you would want to call this function.
EnterDigit("whatever number you want to enter to the keypad")
2 Likes
Thanks! both of yall helped me a lot, and finally understanding what that weird … thing was i saw in prints.
1 Like