How do I make a Typing minigame?

I am trying to create a minigame which requires users to press random letters on the keyboard, in a certain amount of time(1-2 seconds)
Also, the sistem should detect when the players press the right letter and show another random letter.
Something like this:

And, I just can figure out how to do it.
I tried this but it didn´t work:

 local letters = require(script.ModuleScript)
local UserInput = game:GetService("UserInputService")
local duration = 100000
local RightLetter = script.RightLetter
`while duration > 0 do
RightLetter.Value = false
local letter = letters.SelectLetter()
script.Parent.Text = letter.Name
UserInput.InputBegan:Connect(function(input)
	if input.KeyCode == letter then
	print("Right letter")
	RightLetter.Value = true
	elseif input.KeyCode ~= letter then
	end
end)
if RightLetter.Value == true then
print("Right letter")
continue
end
	print(RightLetter.Value)
duration = duration - 1.5
wait(3.5)
end
1 Like

What is letter? Letter has to be of type Enum.KeyCode

Sorry my bad, the module has a list of diferent KeyCodes

I’m not the type to give out code but I feel you would have trouble understanding how to do it. So…

Here’s one way you can go about doing that:

local letters = require(script.ModuleScript)
local UserInput = game:GetService("UserInputService")
local panicking = true

local function CODE_RED()
    -- use a co-routine to ensure the countdown doesn't interfere with the script
    coroutine.wrap(function()
        -- choose a random start time
        local startDur, endDur = math.random(1, 2), 0

        -- countdown from 'startDur' variable to 'endDur' variable
        for i = startDur, endDur, -1 do
            if i == 0 then
                panicking = false
                print("phew, looks like everything returned to normal :D")
            end
        end
    end)()

    while panicking do
        -- choose an arbitrary letter
        local randomLetter = letters.SelectLetter()

        -- waits for the user to press a key
        local input, gp = UserInput.InputBegan:Wait()

        -- if the key the user pressed is equal to the arbitrary letter that was chosen...
        if input.KeyCode == randomLetter then
            -- they got it right!
            print("correct!")
        else
            -- they didn't get it right :(
            print("incorrect :(")
        end
    end
end

Hopefully this helps :smiley:

1 Like

Hi!
Sorry for the delay, covid hit me pretty hard, the code works very well, I edited the co-rutine beacause it wasn´t working(the game was infinite), and also to make it simpler, here´s what I did:

	coroutine.wrap(function()
		-- choose a random start time
		local duration = 5
		-- countdown from 'startDur' variable to 'endDur' variable
		for i = duration, 0, -1 do
		warn(i)
			if i == 0 then
				panicking = false
				warn("Minigame finished")
				print("phew, looks like everything returned to normal :D")
			end
		wait(1)
		end
	end)()--Thanks @Kl_umz!!

Thanks for all!
Also, I’m trying to limit time to write the letter, so, if a player doesn’t write the right letter in a certain time, it detects it and skip to another letter.

2 Likes