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

How to combine animation with a pressed key to run it?

Asked by 7 years ago

So when I press a key I want to run an animation. I don't know how to use user input service and how to use it with an animation. I have one more question if I hold the key will the animation will stop at the last frame of the animation or it will loop the animation?

2 answers

Log in to vote
0
Answered by 7 years ago
game:GetService("UserInputService").InputBegan:connect(function(Key, Chat)
if Key.KeyCode = Enum.KeyCode.Q and not Chat then -- This makes it so when you push Q, and you're not typing in the chat, the animation will play
AnimTrack:Play()
end
end)


-- Only add this next part if you want the animation to stop when you release the key

--[[ game:GetService("UserInputService").InputEnded:connect(function(Key, Chat)
if Key.KeyCode = Enum.KeyCode.Q and not Chat then -- This makes it so when you release Q, and you're not typing in the chat, the animation will stop
AnimTrack:Stop()
end
end) ]]--
0
Thx tecady2111 12 — 7y
0
Np animelover6446 41 — 7y
Ad
Log in to vote
0
Answered by
blowup999 659 Moderation Voter
7 years ago
local UIS = game:GetService("UserInputService")
UIS.InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.E then
        animationTrack:Play()
    end
end)

Answer this question