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 it so that when I press a key, it plays an animation?

2 answers

✓ Accepted answer

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 :)

3 comments

0

Is input the key I press? And what's gameProcessed?

0

Nvm I get it.

0

if you want to now the key you pressed you should use if input.KeyCode == Enum.KeyCode.R then

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.