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

How to use numbers on keyboard for input?

Asked by 5 years ago

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.

1
They’re all words, meaning 1, will be One Ziffixture 6913 — 5y
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. httpOmqCxpcake 70 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
oooh I understand now thank you very much, idk why i didn't think of that. EmStellarStudio 7 — 5y
Ad

Answer this question