Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to check if inputbegan key is in a table?

Asked by
Infocus 144
4 years ago

Ive tried something like this aint I don't think it works. There is no output.

local keys = {
"A";
"D";
}

uis.InputBegan:connect(function(key, process)
    if key.KeyCode == keys[key] then
    --
    end
end)

2 answers

Log in to vote
4
Answered by 4 years ago

You were close. Do something like this:

local keys = {
Enum.KeyCode.A;
Enum.KeyCode.D;
}

uis.InputBegan:connect(function(key, process)
    if table.find(keys, input.KeyCode) then
    --
    end
end)
1
ty ty Infocus 144 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You can try a for loop and check if any values match the key.

local keys = {"A", "D"}

uis.InputBegan:Connect(function(key,process)
    for i,v in pairs (keys) do
        if v == key.KeyCode then
        -----
        break
    end
end)

0
Is there any way without looping? Infocus 144 — 4y

Answer this question