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

How would you keycode space bar (key code = 32)?

This is my code so far:

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.32 then
		print("Space was pressed")
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

Erroring at line 2. Dont know how to refer to a number.

1 answer

✓ Accepted answer

The space bar has a value of 32, not a name. Use this page as a reference:

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Space then
        print("Space was pressed")
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

1 comment

0

Derp... I thought the name was just a obvious description, not an actual registered name. Thanks. +1

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