Hi there, I’ve been trying to make a memory game using a keypad. What I mean is, the keypad will tell you the code, and you will have to memorize it to get it, and then you have to repeat what it does: if they click it as the keypad says, the door opens; if you get it wrong, the buttons will fade to red, and you will have to redo the pattern.
I am going to introduce a far simpler example here, so you can get how is that supposed to work, but idea is simple. All you have to do is keep track of player’s input and check if the answer fits to the index value.
Example:
local Code = {3,2,6,6,7}
local PlayerInput = {3,2,6,6,7} --expected output would be true
local Output = true
for i = 1,#Code do
Output = Code[i] == PlayerInput[i] --check if player's input is correct
if not Output then
break
end
end
return Output
that’s the internal how you would verify if players click the same buttons as the computer does.
keep track of what the cpu made, then keep track of the current player’s inputs, once the player’s input count reaches the count of cpu digits you can easily check if the player is right
as for detecting input in a numpad I would suggest a lookup dictionary like this
local UIS = game:GetService("UserInputService")
local Lookup = {
[Enum.KeyCode.Num1] = 1;
[Enum.KeyCode.Num2] = 2;
--etc
}
UIS.InputBegan:Connect(function(Input)
local Value = Lookup[Input.KeyCode]
--value is the number that corresponds to the numpad number they pressed
if Value then
ApplyInput(Value)--run a function to apply numpad input here
end
end)