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

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

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

✓ Accepted answer

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)

2 comments

0

and it prints everytime because it detects if s is true

0

which it is

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