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

Is there a more efficient way to detect if the player presses WASD?

Or would I have to go through and write

if (inputObject.KeyCode == Enum.KeyCode.W) then
	--Code
end

for each one?

3 answers

You can print it out by implementing something like this :

if (inputObject.KeyCode == Enum.KeyCode.W) then
       print("Key pressed!")
end

That is the most efficient way to detect player keys. Maybe you need to change the code so that it can function better.

perhaps you're looking for something like

local keys = "WASD"
if string.find(keys, (tostring(inputObject.KeyCode)):sub(14)) then
	-- do stuff
end

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