I have a script that plays an animation whenever W,A,S, or D are pressed . The animation ends in a loop, however I was wondering if there was a way I could get it to stop the animation when the key was released? Would it work with a looped animation? Do I need to remove the loop? I've tried adding an additional chunk of code using Service.InputEnded but the animation continued to play.
--EDIT-- Script now fires when key is released, And I've changed the animation to one that doesn't loop. It still doesn't work quite right however.
local Service = game:GetService("UserInputService")
local animation = Instance.new("Animation")
local player = game.Players.LocalPlayer
local char = player.Character
Service.InputBegan:connect(function(input, recieved)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.W then
repeat
print('Input W')
animation.AnimationId = "http://www.roblox.com/Asset?ID=313344129"
local animTrack = player.Character.Humanoid:LoadAnimation(animation)
animTrack:Play()
wait(1)
until
Service.InputEnded:connect(function(input, recieved)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.W then
print('Input W stahped')
local animTrack = player.Character.Humanoid:LoadAnimation(animation)
animTrack:Stop()
end
end
end)
end
end
end)

2 comments
that script wont stop the loop.
Id suggest to use the "Animate" script found inthe default player, all you will need to do is change the animation ids to your own