I’m struggling with making the running animation work properly. See, it does work when you press Right Shift but the problem is that it doesn’t stop when I release the key. How do I fix this please?
local Players = game:GetService("Players")
local anim = "rbxassetid://9724554081"
local runs = 25
local walks = 15
local P = Players.LocalPlayer
local a = Instance.new("Animation")
a.AnimationId = anim
local function beginScript(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.RightShift then
P.Character.Humanoid.WalkSpeed = runs
local lanim = P.Character.Humanoid:LoadAnimation(a)
lanim:Play()
end
end
end
end
local function endScript(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.RightShift then
P.Character.Humanoid.WalkSpeed = walks
local lanim = P.Character.Humanoid:LoadAnimation(a)
lanim:Stop()
end
end
end
end
userInput.InputBegan:Connect(beginScript)
userInput.InputEnded:Connect(endScript)
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local RS = game:GetService("RunService")
local Player = Players.LocalPlayer
local Character = Player.CharacterAppearanceLoaded:Wait() and Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local runs = 25
local walks = 15
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://9724554081"
local RunAnimation = Animator:LoadAnimation(Animation)
Animation:Destroy()
local KeyCode = Enum.KeyCode.LeftControl
local function Run(Key, gameProcessed)
if gameProcessed then return end
if Key.KeyCode == KeyCode then
Humanoid.WalkSpeed = runs
RunAnimation:Play()
repeat RS.Heartbeat:Wait()
until not UIS:IsKeyDown(KeyCode)
Humanoid.WalkSpeed = walks
RunAnimation:Stop()
end
end
UIS.InputBegan:Connect(Run)
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local RS = game:GetService("RunService")
local Player = Players.LocalPlayer
local Character = Player.CharacterAppearanceLoaded:Wait() and Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
print(Character, Humanoid, Animator)
local runs = 25
local walks = 15
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://9724554081"
local RunAnimation = Animator:LoadAnimation(Animation)
Animation:Destroy()
local KeyCode = Enum.KeyCode.RightShift
local function Run(Key, gameProcessed)
if gameProcessed then return end
if Key.KeyCode == KeyCode then
Humanoid.WalkSpeed = runs
RunAnimation:Play()
repeat RS.Heartbeat:Wait()
until not UIS:IsKeyDown(KeyCode)
Humanoid.WalkSpeed = walks
RunAnimation:Stop()
end
end
UIS.InputBegan:Connect(Run)