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

Can't get this to work when i click the space key?

Asked by 6 years ago
Edited 6 years ago
function onKeyPress(inputObject, gameProcessedEvent) 
    if inputObject.KeyCode == Enum.KeyCode.Space then

print("hi")

    end
end

1 answer

Log in to vote
0
Answered by
4D_X 118
6 years ago

You aren't calling the function. So basically, the script can use those lines of code, but not until you say it can. This is in a local script by the way. The efficiant way of doing this is...

game:GetService('UserInputService').InputBegan:connect(function(inputObject)
    if inputObject.KeyCode == Enum.KeyCode.Space then

print("hi")

    end
end)

Refer to http://wiki.roblox.com/index.php?title=API:Class/UserInputService/InputBegan for even more help

Ad

Answer this question