How do I make this?

Hey DevForum, I wanted to ask how I can accomplish this random key pressing system. (Watch the video below, skip to 0:35)

The Testing Gate - YouTube (skip to 0:35)

You can pick a key from a list of keys and wait for the player to press it.

By using UserInput Service

–Random text cause of char limit

how would i make it be random and make it show on the gui?

Maybe something like this:

local letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
local letterBoxes = {}

-- Create 5 text boxes to display letters
for i = 1, 5 do
  local letterBox ="TextLabel")
  letterBox.Size =, 50, 0, 50)
  letterBox.Position =, (i-1)*60, 0, 0)
  letterBox.BackgroundColor3 =, 1, 1)
  letterBox.BorderColor3 =, 0, 0)
  letterBox.Text = ""
  letterBox.Parent = script.Parent
  table.insert(letterBoxes, letterBox)

-- Function to display a random letter in each text box
local function setLetters()
  for i = 1, 5 do
    local randomIndex = math.random(1, #letters)
    letterBoxes[i].Text = letters[randomIndex]

-- Call the setLetters function

This code was AI generated from:

ohhh ok thank you. and how would i use user input service?

Something like this I think.

function checkLetter(key)
  if textBox1.Text == key then
    textBox1.Text = ""
  elseif textBox2.Text == key then
    textBox2.Text = ""
  elseif textBox3.Text == key then
    textBox3.Text = ""
  elseif textBox4.Text == key then
    textBox4.Text = ""
  elseif textBox5.Text == key then
    textBox5.Text = ""

function onKeyPressed(inputObject, gameProcessedEvent)
  local key = inputObject.KeyCode.Name


This code was AI generated from:

1 Like

thank you so much it now works

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.