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

How to make a key event?

Asked by
enzdude 10
8 years ago

On my game, I want to make a key event to where if you press "c", you get down on the floor, but slower then usual.

3 answers

Log in to vote
1
Answered by 8 years ago

Warning: This question could be Marked as not constructive since you have provided us with any effort of you trying to accomplish this on your own.

If you want to make a function that triggers by a certain Key then I suggest you use UserInputService and a If statement.

game:GetService("UserInputService").InputBegan:connect(function(Key,Typing)--The second argument "Typing" is a Boolean value that indicates whether or not the Player is Typing.
    if Typing == false and Key.KeyCode == Enum.KeyCode.C then--This checks if the Player isn't Typing as well as if the C key has been pressed
        --YourCode
    end
end)

~UserOnly20Charcters, Hoped I helped you to answer your question! If you have any further question, don't hesitate to comment below!!

0
Thanks :D enzdude 10 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
if key == "x" then -- change the 'x'
-- do stuff
end)
0
I strongly suggest that you shouldn't use KeyDown event as its Deprecated! UserOnly20Characters 890 — 8y
0
It's the 'basic' scripting, there's nothing wrong with it. HMNapoleon 35 — 8y
Log in to vote
0
Answered by 8 years ago
function keypress(UserInput, gameProcessedEvent)
if UserInput.KeyCode == Enum.KeyCode.R then
--YOUR CODE
game:GetService("UserInputService").InputBegan:connect(keypress)
end

Use UserInputService, avoid keydown since its deprecated.

0
Do not use KeyDown it's a bad way to get key input. LightModed 81 — 8y

Answer this question