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

Function keyDown(key) how to?

I have a script here

function keyDown(key)
	if key == "e" then
script.Parent.Parent.Frame.Visible = true
script.Parent.Visible = false
script.Parent.Parent.Frame.Play.Script.Disabled = false
	end
end 

The problem is, how do you make it so the script activates when you press esc?

Do you type in Esc, Escape, etc.

1 answer

✓ Accepted answer

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

Here is a list of the ASCII characters used in Lua, if you look down a bit, you can see that no. 27 is for the escape key.

In order to detect what key was pressed, we need to convert the key (Which is a string) into it's ASCII decimal representation, and then we can check to see if the key is really the escape key.

To convert a string (Ie: "a") into a decimal (65), we use string.byte(string).

Since we know that the ASCII value of the esc key is 27, we can use string.byte to see if they pressed the escape key.

function keyDown(key)
    if string.byte(key) == 27 then
script.Parent.Parent.Frame.Visible = true
script.Parent.Visible = false
script.Parent.Parent.Frame.Play.Script.Disabled = false
    end
end 

1 comment

0

Thanks!

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