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
5 years ago

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

01local keys = {
02"A";
03"D";
04}
05 
06uis.InputBegan:connect(function(key, process)
07    if key.KeyCode == keys[key] then
08    --
09    end
10end)

2 answers

Log in to vote
4
Answered by 5 years ago

You were close. Do something like this:

01local keys = {
02Enum.KeyCode.A;
03Enum.KeyCode.D;
04}
05 
06uis.InputBegan:connect(function(key, process)
07    if table.find(keys, input.KeyCode) then
08    --
09    end
10end)
1
ty ty Infocus 144 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

1local keys = {"A", "D"}
2 
3uis.InputBegan:Connect(function(key,process)
4    for i,v in pairs (keys) do
5        if v == key.KeyCode then
6        -----
7        break
8    end
9end)
0
Is there any way without looping? Infocus 144 — 5y

Answer this question