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

Make a run script stop the animation when holding still despite holding space?

Asked by 2 years ago
Edited 2 years ago

I'm trying to create a LocalScript where when the player holds the shift key, a run animation will play and their speed will be set. I also want it to stop playing when the shift key is unheld. Unfortunately, I cannot figure out how to get the animation to stop when the player is holding still, as the only method i know of (detecting Humanoid.Running) does not seem to work in this case. Here is the code that works fine but runs in place:

local UIS = game:GetService('UserInputService')
local player = game.Players.LocalPlayer
local character = player.Character
local running = false
local Humanoid = character:WaitForChild("Humanoid")


UIS.InputBegan:connect(function(input)
 if input.KeyCode == Enum.KeyCode.LeftShift then
  character.Humanoid.WalkSpeed = 23
  local Anim = Instance.new('Animation')
    Anim.AnimationId = 'rbxassetid://9127242458'
  PlayAnim = character.Humanoid:LoadAnimation(Anim)
  PlayAnim:Play()
  running = true
 end
end)


UIS.InputEnded:connect(function(input)
 if input.KeyCode == Enum.KeyCode.LeftShift then
  character.Humanoid.WalkSpeed = 16
  PlayAnim:Stop()
  running = false
    end
end)

I would greatly appreciate it if someone could tell me what I am supposed to use to detect when the player is not moving.

Answer this question