Help With Fixing My Running Script

Here is my code

local Human = script.Parent:WaitForChild("Humanoid")

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character

UserInputService.InputBegan:connect(function(INP) 
    if INP.KeyCode == Enum.KeyCode.LeftControl then
        Human.Running:Connect(function(speed)
            if speed < 6 then
                Character.Humanoid.WalkSpeed = 18.5
                local Anim = Instance.new('Animation')
                Anim.AnimationId = 'rbxassetid://5709810264'
                PlayAnim = Character.Humanoid:LoadAnimation(Anim)
                PlayAnim:Play()
            elseif speed > 6 then
                UserInputService.InputEnded:connect(function(INP) 
                    if INP.KeyCode == Enum.KeyCode.LeftControl then
                        Character.Humanoid.WalkSpeed = 7.5
                        PlayAnim:Stop()
                    end
                end)
            end
        end)
    end
end)

This is my issue!


Here’s a video showing what’s happening/what’s wrong
2020-09-19 17-12-17|video

Thank you for your time!

Edit : I managed to get it working! Thank you @EsplishData for your help!

Hello!
You are trying to stop animation that does not exist instead of using

PlayAnim:Stop()

Use

for _,track in pairs(Character.Humanoid:GetPlayingAnimationTracks()) do -- Looping all playing tracks and stopping them
      track:Stop()
end
Local IdleAni = Character.Humanoid:LoadAnimation(Character.Animate.idle.Animation1) -- This will loads players idle animation
IdleAni:Play() 

I hope it will help you!

1 Like

Would this be my code then?

local Human = script.Parent:WaitForChild("Humanoid")

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character

UserInputService.InputBegan:connect(function(INP) 
	if INP.KeyCode == Enum.KeyCode.LeftControl then
		Human.Running:Connect(function(speed)
			if speed < 6 then
				Character.Humanoid.WalkSpeed = 18.5
				local Anim = Instance.new('Animation')
				Anim.AnimationId = 'rbxassetid://5709810264'
				PlayAnim = Character.Humanoid:LoadAnimation(Anim)
				PlayAnim:Play()
			elseif speed > 6 then
				UserInputService.InputEnded:connect(function(INP) 
					if INP.KeyCode == Enum.KeyCode.LeftControl then
						Character.Humanoid.WalkSpeed = 7.5
						for _,track in pairs(Character.Humanoid:GetPlayingAnimationTracks()) do
							track:Stop()
						end
						local IdleAni = Character.Humanoid:LoadAnimation(Character.Animate.idle.Animation1)
						IdleAni:Play() 
					end
				end)
			end
		end)
	end
end)

I tried it out and it doesn’t seem to work.

edit : I figured it out