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

How to read numbers (not keypad) with ContextActionService?

I am making a game where pressing the top row of numbers toggles different vehicle options using ContextActionService. No tools are in the game, so using these numbers won't matter.

This works:

function onKey(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin then
print("Ok")
end
end

game.ContextActionService:BindAction("hit", onKey, false, "q")

This works to

game.ContextActionService:BindAction("hit", onKey, false, Enum.KeyCode.Space)

But these don't

game.ContextActionService:BindAction("hit", onKey, false, "1")

game.ContextActionService:BindAction("hit", onKey, false, Enum.KeyCode.One)

1 answer

game.ContextActionService:BindAction("hit", onKey, false, Enum.KeyCode.One)

switch it to "1" instead of "One"

game.ContextActionService:BindAction("hit", onKey, false, Enum.KeyCode.1)

or you can try to do this

--By AlienMister
-- number 1 down

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.KeyDown:connect(function (key)
if key == 1 then
print 'Success, the number "1" has been pressed on your keyboard!'
print '"1" has been purchased!'
else
print'no success'
end
end)

if it dont wrk then try entering the key code of one and/or the byte and then convert it. k?

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