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

How to use numbers on keyboard for input?

I am using Roblox wiki's code for this, but ran into a quick problem and can't find it on wiki or anything. How do I use numbers for keyboard input. I tried if inputObject.KeyCode == Enum.KeyCode.1 then but I can't use numbers for keycode? I am stuck.

2 comments

1

They’re all words, meaning 1, will be One

1

This question is quite simple, really. Refer to https://developer.roblox.com/api-reference/enum/KeyCode . I am sure like most programming languages, the identifier mustn't start with a number.

1 answer

✓ Accepted answer

Every Enum.KeyCode is a word, not a number. To track numbers, use the words that go with them:

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.One then -- Key press detects the number 1
		-- other code
	elseif key.KeyCode == Enum.KeyCode.Two then -- Same here
		-- some more code
	end
end)

1 comment

0

oooh I understand now thank you very much, idk why i didn't think of that.

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