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

Why does the "or" function not work with InputBegan?

Asked by
Sorukan 240 Moderation Voter
4 years ago

My script is pretty simple, i'm just trying to print something whenever i press either the W or the S key using the "or" function along with InputBegan, For some reason though, the code prints whenever i press any key on the keyboard not just W or S.

local W = Enum.KeyCode.W
local S = Enum.KeyCode.S

local UIS = game:GetService('UserInputService')

UIS.InputBegan:Connect(function(input)

    if input.KeyCode == W or S then
        print('working')
    end

end)

I really don't understand why it doesn't work when it seems like it should...

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

the problem is that you didn't write the whole thing again, heres the script:

local W = Enum.KeyCode.W
local S = Enum.KeyCode.S

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == W or input.KeyCode == S then
        print("working")
    end
end)
0
and it prints everytime because it detects if s is true AnasBahauddin1978 715 — 4y
0
which it is AnasBahauddin1978 715 — 4y
Ad

Answer this question