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

Why isn't this KeyDown working?

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

✓ Accepted answer

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.

2 comments

0

I have removed the backpack using the Core thingy. If the backpack isnt there then can I still use your one?

0

UserInputService will work if it is there or not!

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