i know some basic scripting, but i would like to know how to do something with a key pressed
✓ ANSWER ACCEPTED
how do i make something happen when i hit a certain key?
3 answers
✓ Accepted answer
So, you're asking for a keydown event and all you need to do is this.
--In a local script
local Player = game.Players.LocalPlayer --Get the player
local Mouse = Player:GetMouse() --Get the Player's mouse
Mouse.KeyDown:connect(function(key)
key = key:lower()
if key == "" then -- in strings put the key for example q
--What you want the player to do
end
end)
This wiki post might be a good help for you: http://wiki.roblox.com/index.php?title=Keyboard_input
And it clearly states that the mentioned KeyDown way of getting Keyboard Input is deprecated and should not be used.
This works in my GUI put into StarterGUI, so hopefully you can find use for this:
local player = game.Players.LocalPlayer
function clicked(Key)
if Key == "z" and player.Name == "USERNAME" then
game.Players.LocalPlayer.PlayerGui.GUINAME.FrameName.Visible = true
end
end
game.Players.LocalPlayer:GetMouse().keyDown:connect(clicked)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
https://www.youtube.com/watch?v=G5NUPjQVaV0 -- keyDown video
This is something that can be achieved through simple research, and is not a scripting question. This is a lazy form of a request.