An issue with tables

Im trying to make a simple movement script. In the code below I list out all the keys that will trigger movement below in a table. Below that is the event, in the event it tries to check whether or not the input given is inside the table. For some reason, it doesn’t work, but it worked when I was using a dictionary table instead. Any suggestions?

local MovementKeys = {
	Enum.KeyCode.W,
	Enum.KeyCode.A,
	Enum.KeyCode.S,
	Enum.KeyCode.D
}

UIS.InputBegan:Connect(function(Input)
	if MovementKeys[Input.KeyCode] then
		print "test"
	end
end)

Because the table you have set up is has numbers as keys, you’re trying to get a KeyCode as a key, which doesn’t work

If you want this to work with a table, use table.find

if table.find(MovementKeys, Input.KeyCode) then
1 Like