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

How do I Bind a function successfully to a number/non-letter?

function KeyPrimary(actionName, userInputState, inputObject)
	print(userInputState)
	if userInputState == Enum.UserInputState.Begin then
		print("1 was pressed")
	end
end
 
game.ContextActionService:BindAction("keyPress", KeyPrimary, false, Enum.KeyCode.One)

When I use this it only prints the userInputState as I let go of 1, how come it doesn't work when I push it down?

1 answer

✓ Accepted answer
plr = game.Players.LocalPlayer
char = plr.Character
mouse = plr:GetMouse()

mouse.KeyDown:connect(function(key)
	print("Button Pressed: "..key)
	if key:byte() == 17 then  -- up arrow
		print("find more bytes ^ look at bottom of answer!")
	end
end)
	

So basically keybinding a "number" such as 1-9 or 0 cannot be done; you have to do, key:bytes which the bytes refer to the data (numbers) which refer the a keyboard input, enjoy! for more keyboard inputs; go to http://wiki.roblox.com/index.php?title=Keyboard_input_(deprecated)

[make sure to add the (deprecated) in the link or look up Keyboard input (deprecated) at the roblox wiki]

1 comment

0

Thanks! I wonder why there is an emun.keycode.one if it doesn't work :/     Edit 2: oooo its used in UserInputServer

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