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

Help with when a player presses the enter key?

Asked by 6 years ago
function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == 13 then
        print("enter")
    end
end

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

The enter key is 13 but this doesn't work so what do I do. I am just trying to print "enter" then the player presses enter.

0
where is this code located? Le_Teapots 913 — 6y
0
^ ThatPreston 354 — 6y
0
Localscript goldstorm950 65 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Here is one way of doing it

-- Declaration Section 
local UserInputService = game:GetService("UserInputService")

-- Processing Section 

local function onPressKey (InputObject, GameProcessedEvent)
    if InputObject.KeyCode == Enum.KeyCode.Return then
        print("Enter/Return has been pressed!")
    end
end

-- Connecting Section
UserInputService.InputBegan:Connect(onPressKey)
0
I assume you forgot to include: if GameProcessedEvent then return end right at the start of Processing Section. DoYouKnowHowToRead -13 — 6y
0
^ It is required however I think the op is more than enough to handle it. Axceed_Xlr 380 — 6y
Ad

Answer this question