Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to check if inputbegan key is in a table?

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

✓ Accepted answer

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 comment

1

ty ty

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)

1 comment

0

Is there any way without looping?

This discussion is preserved as it was. New answers, comments, and votes are closed.