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

Why isn't this KeyDown working?

Asked by 10 years ago
if key:byte() == "1" then
    print("1 pressed")
elseif key:byte() == "2" then
    print("2 pressed")
end

How come this dosent check to see if a player has pressed 1 or 2? I want it so when your player presses 1 then it prints "1 pressed"

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

The number keys are reserved for the Backpack CoreGUI. I strongly suggest looking into UserInputService. With this you can check a large variety of inputs, including keyboard button presses, regardless of gamestate.

local UserInput = game:GetService('UserInputService')

UserInput.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.One then
        print('1 pressed')
    elseif input.KeyCode == Enum.KeyCode.Two then
        print('2 pressed')
    end
end)

Note: UserInputService must be used inside of a local script.

0
I have removed the backpack using the Core thingy. If the backpack isnt there then can I still use your one? NinjoOnline 1146 — 10y
0
UserInputService will work if it is there or not! BlackJPI 2658 — 10y
Ad

Answer this question