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

How to read numbers (not keypad) with ContextActionService?

Asked by 8 years ago

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

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

Ad

Answer this question