I'm trying to create a new walk animation, which almost fully works. With the code I currently have, I can get the animation to play, loop and override the regular walk animation, but I can't get it to stop when the player isn't pressing a certain key. How do I get this to happen? The code below is what I am currently using.
--The Animation
local walkanim = Instance.new("Animation")
--animationlinkgoeshere will be replaced with the actual link
walkanim.AnimationId = "animationlinkgoeshere"
--Player
local plr = game.Players.LocalPlayer
--UserInputService
local uis = game:GetService('UserInputService')
--Input Function
function Input(i)
--Check key
if i.KeyCode == Enum.KeyCode.W then
animTrack = plr.Character.Humanoid:LoadAnimation(walkanim) -- Load animation into Humanoid
animTrack:Play()
end
end
function onSelected()
--Connect function
uis.InputBegan:connect(Input)
end
script.Parent.Selected:connect(onSelected)
As you can see, I've made it so that the animation will play when W is pressed.

2 comments
This works perfectly, thank you.
No problem.