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

Help with when a player presses the enter key?

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.

3 comments

0

where is this code located?

0

^

0

Localscript

1 answer

✓ Accepted answer

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)

2 comments

0

I assume you forgot to include: if GameProcessedEvent then return end right at the start of Processing Section.

0

^ It is required however I think the op is more than enough to handle it.

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