Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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

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. iamnoamesa 674 — 8y

3 answers

Log in to vote
0
Answered by 8 years ago

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)
Ad
Log in to vote
0
Answered by 8 years ago

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.

Log in to vote
0
Answered by
Smaltin 46
8 years ago
Edited 8 years ago

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)

Answer this question