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

How do I make it so that when I press a key, it plays an animation?

Asked by
LawlR 182
6 years ago
Edited 6 years ago

What the title says. I can do the animation part, just don't know how to detect when the player presses a key. (Without having a tool equipped)

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You should use userinputservice (as keydown is ripped)

Like this

local UserInputService = game:GetService('UserInputService')

function onInputBegan(input,gameProcessed)
    -- Code
end

UserInputService.InputBegan:connect(onInputBegan)

Userinputservice has inputbegan and inputended wich both equal to keydown and keyup.

If you have any more questions, just ask :)

0
Is input the key I press? And what's gameProcessed? LawlR 182 — 6y
0
Nvm I get it. LawlR 182 — 6y
0
if you want to now the key you pressed you should use if input.KeyCode == Enum.KeyCode.R then User#20388 0 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

theUserInputService = game:GetService("UserInputService") -- this is what it is

theUserInputService.InputBegan:Connect(function(key, processedevent) -- this is the key-bind

if processedevent then return end -- this is so animations don't play while you are typing

if key.KeyCode == Enum.KeyCode.Z then -- this is the key you would press, change Z to yours.

(animation stuff go here)

end

end)

Answer this question