Weird errors popping up inside of output

Hello, I am making a flash project and I’m having trouble with the animation play. It works but it will not continue after pressing stop and will error before sprinting. Here’s the source code.

local UserInput = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage:WaitForChild("Events")
local Animation = script:WaitForChild("RunAnimation")
local KeyPressed = nil
local Running = nil

local RunGoal = {
	FieldOfView = 110
}

local RegularGoal = {
	FieldOfView = 110
}



local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.1)
local RunTween = tweenService:Create(workspace.CurrentCamera,tweenInfo,RunGoal)
local WalkTween = tweenService:Create(workspace.CurrentCamera,tweenInfo,RegularGoal)
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

UserInput.InputBegan:Connect(function(Key, IsTyping)
	if Key.KeyCode == Enum.KeyCode.LeftShift and not IsTyping then
		if game.Players.LocalPlayer.Character:WaitForChild("Humanoid").MoveDirection.Magnitude > 0 then
			if KeyPressed == nil and Running == nil then
				KeyPressed = true
				Running = true
				LoadAnimation = Humanoid:LoadAnimation(Animation)
				LoadAnimation:Play()
				EventsFolder:WaitForChild("SpeedOn"):FireServer()
				RunTween:Play()
			elseif KeyPressed == true and Running == true and not IsTyping then
				KeyPressed = nil
				Running = nil
				LoadAnimation:Stop()
				EventsFolder:WaitForChild("SpeedOff"):FireServer()
				WalkTween:Play()
			end
		end
	end
end)

Humanoid.Changed:Connect(function()
	if Humanoid.Jump and LoadAnimation.IsPlaying and Running == true then
		LoadAnimation:Stop()
		Running = nil
	end
end)

Humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Landed then
		LoadAnimation:Play()
		Running = true
	end
end)

Humanoid.Running:Connect(function(Speed)
	if Speed > 0 and not LoadAnimation.IsPlaying and Running == nil then
		LoadAnimation:Play()
		RunTween:Play()
		Running = true
	elseif Speed <= 0.01 and LoadAnimation.IsPlaying and Running == true then
		LoadAnimation:Stop()
		WalkTween:Play()
		Running = nil
	end
end)

Output


Video

[You can clearly see the flaws of this script]

Only works again if you jump then press shift???

that method is deprecated, it’s best do Humanoid:WaitForChild("Animator"):LoadAnimation()

It still happens, I the Deprecated way does the safe effect as this

Humanoid:WaitForChild("Animator"):LoadAnimation()

ADD THE ANIMATION ID FTLOG :rofl:

:man_facepalming: there is an animation ID. look at the output

It would’ve said “Animation needs to have an ID” or something like that

sorry man i got confused for a second, thinking that you forgot to add the animation id while fixing the script

Yeah, I probably would’ve mentioned the animation ID problem if i knew it was that lol

You don’t need to do LoadAnimation, do Animation:Play() ! :grin:
Have a nice day ! :yum:

Animation:Play() is under load animation btw

No you didn’t get it ! :grinning:
You need to remove your var load animation and directly do Animation:Play ! :smile:

sorry guys i didn’t explain it better, the problem was the load animation needed to be switched from inside of the function to where the variables where. Good day everyone!