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

How would I Key Bind #'s 0-9 when backpack is disabled?

People told me to use UserinputService. Thing is, I never used it before. So instead of just telling me to use that, show me how you would use it. Please.

Is it possible to convert this to work?:

inputService = game:GetService("UserInputService")

inputService.InputBegan:connect(function(input)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == Enum.KeyCode.Slash then
            print("/ key has been pressed!")
        end
    end
end)

1 answer

✓ Accepted answer

Yes, all you have to do is add the if statements for the key Zero through Nine.

if input.KeyCode == Enum.KeyCode.Zero then
       -- Do stuff when key pressed is zero.
end
if input.KeyCode == Enum.KeyCode.One then
       -- Do stuff when keypressed is one.
end
if input.KeyCode == Enum.KeyCode.Two then
       -- Do stuff when key pressed is two.
end
if input.KeyCode == Enum.KeyCode.Three then
       -- Do stuff when keypressed is three.
end
if input.KeyCode == Enum.KeyCode.Four then
       -- Do stuff when key pressed is four.
end
if input.KeyCode == Enum.KeyCode.Five then
       -- Do stuff when key pressed is five.
end
if input.KeyCode == Enum.KeyCode.Six then
       -- Do stuff when key pressed is six.
end
if input.KeyCode == Enum.KeyCode.Seven then
       -- Do stuff when key pressed is seven.
end
if input.KeyCode == Enum.KeyCode.Eight then
       -- Do stuff when key pressed is eight.
end
if input.KeyCode == Enum.KeyCode.Nine then
       -- Do stuff when key pressed is nine.
end

Sorry for the long code. D:

1 comment

0

Didn't know it was that easy -.- Facepalm

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