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

How can you use keys to make things happen?

I want to know how (when you press a key on your keyboard) something can happen with Roblox LUA.

1 answer

✓ Accepted answer

I'm here man!

You want to use UIS (UserInputService).

Try this:


local key = Enum.KeyCode.LeftShift --Change LeftShift with the key you want, for example, R.

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == key then --code goes here down.
		print("Left Shift was pressed.")
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

It works.

If you want a full list of key codes to use, here they go. Just copy the key you want from the left column, called "Name", behind "Enums", and have fun!

If this works, mark as correct, please, and as always, good scripting! ;)

2 comments

0

Thanks again! (I also friended you in Roblox)

0

Yeah, I saw it. No problem! :D

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