Why can't you have multiple values for one variable?

So doing something like “Local StopKeys = Enum.KeyCode.A and Enum.KeyCode.W” etc. doesn’t work. Why? How can I replace this to make it work?

I’m doing this to both help me and to help other people who search this up.

You can actually:

local x, y, z = 1, 2, 3;

Not really sure what your question is, apologies if I didn’t understand.

You can, you just are using it the wrong way.

Its like trying to do if abc.Value == true or false. That wont work. You have to do local 1, 2 = Enum.KeyCode.A (1), Enum.KeyCode.W (2)

So I have this code I’m working on where I press a key to stop an animation. I want those keys to be W A S and D. When I type “local stopAnimKeys = Enum.KeyCode.W and Enum.KeyCode.A” / S / D, it doesn’t work.

Variables can only have 1 value, because if you want to refer to them you will not know which value you are refering to. Instead you can use tables:

local UIS = game:GetService("UserInputService")
local StopKeys = {Enum.KeyCode.A, Enum.KeyCode.W}


UIS.InputBegan:Connect(function(input, processed)
    if processed then return end
    if table.find(StopKeys, input.KeyCode) then
        --code
    end
end)
5 Likes

1 and 2 can’t be used as variable names

Thanks! This worked for my script and hopefully it can also help other people who are confused!

1 Like

It was an example. I thought that was clear…

1 Like

it was clear, but I don’t think it is bad that I pointed it out