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)
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 = Instance.new("TextLabel")
letterBox.Size = UDim2.new(0, 50, 0, 50)
letterBox.Position = UDim2.new(0, (i-1)*60, 0, 0)
letterBox.BackgroundColor3 = Color3.new(1, 1, 1)
letterBox.BorderColor3 = Color3.new(0, 0, 0)
letterBox.Text = ""
letterBox.Parent = script.Parent
table.insert(letterBoxes, letterBox)
end
-- 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]
end
end
-- Call the setLetters function
setLetters()
This code was AI generated from: https://chat.openai.com/chat
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 = ""
end
end
function onKeyPressed(inputObject, gameProcessedEvent)
local key = inputObject.KeyCode.Name
checkLetter(key)
end
UserInputService.InputBegan:connect(onKeyPressed)
This code was AI generated from: https://chat.openai.com/chat
thank you so much it now works
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.