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

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

Asked by 8 years ago

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

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

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)
0
Derp... I thought the name was just a obvious description, not an actual registered name. Thanks. +1 Orlando777 315 — 8y
Ad

Answer this question