Custom Animations Glitch

Hi DevForum!

I was making a custom walking and running animation, when I encountered an issue.

When the player stops running, the walk animation kind of glitches.

I am using the normal animate script, plus a UIS LeftShift detector. Here is my script:

local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local currentCamera = workspace.CurrentCamera

local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local RS = game:GetService("ReplicatedStorage")

local tweenInfo = TweenInfo.new(0.5)

local runningGoals = {WalkSpeed = 20}
local runningCamGoals = {FieldOfView = 85}

local walkingGoals = {WalkSpeed = 8}
local walkingCamGoals = {FieldOfView = 70}

local isRunning = false

local AnimationsFolder = RS:WaitForChild("Animations")
local Animation = AnimationsFolder:WaitForChild("Animation")

local animations = {
	"rbxassetid://11411302455", -- Run
	"rbxassetid://11411349311" -- Walk
	
}

local runAnim

UIS.InputBegan:Connect(function(input, isTyping)
	if isTyping then return end
	
	if input.KeyCode == Enum.KeyCode.LeftShift then
		
		if not isRunning then
			isRunning = true
			
			local runningTween = TweenService:Create(humanoid, tweenInfo, runningGoals)
			local runningCamTween = TweenService:Create(currentCamera, tweenInfo, runningCamGoals)
			
			runningTween:Play()
			runningCamTween:Play()
			
			Animation.AnimationId = animations[1]
			runAnim = humanoid:LoadAnimation(Animation)
			runAnim:Play()
		elseif isRunning then
			isRunning = false
		
			local walkingTween = TweenService:Create(humanoid, tweenInfo, walkingGoals)
			local walkingCamTween = TweenService:Create(currentCamera, tweenInfo, walkingCamGoals)

			walkingTween:Play()
			walkingCamTween:Play()
			
			runAnim:Stop()
		end
		
	end
end)

And here is a video:

I don’t see a “glitch”.

Can you describe what you are seeing?

Yes, at 0:15, the normal walk plays, which is good, whereas when you stop running and stuff, you kind of don’t have the full animation, it’s a bit glitched.

Animations “jump” from one animation to the next.

Try looking into AdjustWeight on the animations to blend it with others playing at the same time.

https://create.roblox.com/docs/reference/engine/classes/AnimationTrack#AdjustWeight