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

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

Asked by 8 years ago
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

Log in to vote
0
Answered by 8 years ago
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]

0
Thanks! I wonder why there is an emun.keycode.one if it doesn't work :/     Edit 2: oooo its used in UserInputServer tkddude2 75 — 8y
Ad

Answer this question