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

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

Asked by 10 years ago

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

Log in to vote
0
Answered by
Gamenew09 180
10 years ago

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:

0
Didn't know it was that easy -.- *Facepalm* Orlando777 315 — 10y
Ad

Answer this question