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

how do i make something happen when i hit a certain key?

i know some basic scripting, but i would like to know how to do something with a key pressed

2 comments

0

This is something that can be achieved through simple research, and is not a scripting question. This is a lazy form of a request.

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 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.