How do i make it so “if input.keycode == the variable of the random character”?

I have a code in my game that makes a random number, turns it into characters using ascii and i want it so that whenever you type that random character, something will happen.

How do i make it so “if input.keycode == the variable of the random character”?

I have tried finding a solution but idk where to find it.

My game is a coding simulator game where you have to type random numbers given to you for you to code. How do i make it so that it detects the random character input?

Here is my code:

local UserInputService = game:GetService(“UserInputService”)

local TurnOnCompEvent = game:GetService(“ReplicatedStorage”).TurnOnComp

local CompUI = game:GetService(“StarterGui”).CompUI
local Frame = script.Parent.Frame

local NeededInput = math.random(65, 90)
local NeededInputString = string.char(NeededInput)

TurnOnCompEvent.Event:Connect(function()
    wait(0.5)
    Frame.Visible = true
    Frame.NeededInputText.Text = ("Needed Input: " … string.char(NeededInput))
    UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
        -here is the problem
        if input.KeyCode == (Must Be Needed Input, or needed input character var) then
            Frame.TextLabel.Text = (“Wow u coded!”)
        end
    end)
end)

You can just do this:

if input.KeyCode == Enum.KeyCode[NeededInputString] then
     --your code
end
2 Likes

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