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

How can you use the keydown event for numbers? [FIXED]

Asked by 9 years ago
mouse.KeyDown:connect(function(key)
    print(key:byte())
    if key:byte() == 49 and currentslot.Name == "Slot1" then 
    print("1")
usepotion()
elseif key:byte() == 50 and currentslot.Name == "Slot2" then 
    print("2")
usepotion()
elseif key:byte() == 51 and currentslot.Name == "Slot3" then 
    print("3")
usepotion()
elseif key:byte() == 52 and currentslot.Name == "Slot4" then 
    print("4")
usepotion() 
elseif key:byte() == 53 and currentslot.Name == "Slot5" then    
    print("5")
usepotion()
elseif key:byte() == 54 and currentslot.Name == "Slot6" then
    print("6")
usepotion()
elseif key:byte() == 55 and currentslot.Name == "Slot7" then 
    print("7")
usepotion()
elseif key:byte() == 56 and currentslot.Name == "Slot8" then 
    print("8")
usepotion()
end
end)

http://wiki.roblox.com/index.php?title=Taking_keyboard_input http://wiki.roblox.com/index.php?title=File:Ascii_Table.png

The first print I have prints the key.byte, and it works when I press a letter, but not a number. The tabled where I got the numbers from shows both letters and numbers, but the wiki doesn't mention it. Help? How could I solve this?

[Edit 2] Fixed, for bound keys that roblox doesn't want you to use (ex: i and o for camera), use keyup.

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Since you seem to have already found your answer, I suggest looking into the User Input Service.

It's exactly the same as using KeyUp and KeyDown and whatnot (although the names are changed), but it's guaranteed to work regardless of game state. Mouse objects can break under certain situations.

Plus you can use iDevice-style touch controls with it.

If you want to see an example of it in use, I can send you the source of a game I am working on that uses it.

1
Nah, but thanks for the help! tkddude2 75 — 9y
Ad

Answer this question