So I have a run script and the animation plays whenever the character is holding left shift and it increases player speed. However if the character is not moving but left shift is still being held the running animation will continue to play. I was wondering if anyone can update my script to play the idle animation if the character isn’t moving while the script is still active.
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 35 --run speed
local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://15718018186'
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim.Priority = Enum.AnimationPriority.Movement
PlayAnim:Play()
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 16 --default walk speed
PlayAnim:Stop()
end
end)
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
PlayAnim:Stop()
wait(.8)
if Character.Humanoid.WalkSpeed == 35 then
PlayAnim:Play()
end
end
end)