I want to make it do something when you press Enter, but if you do onKeyDown with strings, you can't make a string version of Enter, and using numbers, I don't know the number for Enter.
ASCII
(or American Standard Code for Information Interchange) is an encoding system in which English characters are converted to decimal
numbers (referred to as their byte codes), so machines can convert those decimal numbers to machine code (binary). You can look at all the ASCII characters in this table.
Just to make things clear, you don't have to know every single number that corresponds to every single ASCII character. In fact, we have functions that can make this conversion for us in Lua's string library
, called char and byte. Using string.char
will convert any byte code (ASCII encoded character), back into plain text. string.byte
on the other hand, takes a string in plain text, and converts it to it's ASCII representation.
The reason I'm explaining all of this, is because when you use byte
(either from the string library, or just as a method on a string), what you're doing is converting that character to ASCII. So to answer your question, you'd compare 13
to the byte code of the key pressed, since 13 is the Enter key in ASCII.
Even though this solves your current problem, there's still more to consider. ROBLOX has integrated a service called UserInputService for quite some time now, and it is the preferred method of collecting input from a user. Input collected by the PlayerMouse shouldn't be used anymore.
I highly suggest you switch from using the PlayerMouse for input, to UserInputService. It may take some tampering with to get used to, but it's a lot better and you'll enjoy using it once you get the hang of it. Anyway, hope this helped, just let me know if you have any questions.