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)
How do I make it so that when I press a key, it plays an animation?
2 answers
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
Is input the key I press? And what's gameProcessed?
Nvm I get it.
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.

1 comment
https://wiki.roblox.com/index.php?title=API:Class/UserInputService