Animation does not stop as it's supposed to

Hello everyone!
The animation in my game does not stop when it’s supposed to, I’ve checked it’s length and everything’s fine, and other anims do not have such problem, it’s only about dash, and I couldn’t figure out what’s the issue.
As you can see on the gif “Hello” here prints out just fine when it’s supposed to end, but the animation stops at last frame for 0.2-0.3 seconds…?
RobloxStudioBeta_DDQUVr9Rsk

I can just task.wait(animation.Length) and stop it(sometimes it doesn’t work), I’ve also tried :AdjustWeight(), but couldn’t figure out what’s the problem…

Here’s the code I use for dash’s animation:

local UIS = game:GetService('UserInputService')
local Players = game:GetService('Players')
local RS = game:GetService('ReplicatedStorage')
local Player = Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild('Humanoid')
local Animator = Humanoid:WaitForChild('Animator')
local HRP = character:WaitForChild('HumanoidRootPart')
local dashEvent = RS.EventsAndFunctions.Dash
local CD = false
local direction
local animations = {
	['W'] = Animator:LoadAnimation(RS.Animations.Other.Dash.DashW);
	['A'] = Animator:LoadAnimation(RS.Animations.Other.Dash.DashA);
	['S'] = Animator:LoadAnimation(RS.Animations.Other.Dash.DashS);
	['D'] = Animator:LoadAnimation(RS.Animations.Other.Dash.DashD);
}
--
UIS.InputBegan:Connect(function(input, isTyping)
	if Player:GetAttribute('Spawned') == false or not Player:GetAttribute('Spawned') then return end
	if isTyping == true or Humanoid:GetAttribute('Dashing') == true or Humanoid:GetAttribute('Debounce') > 0 or Humanoid:GetAttribute('isTalking') == true or Humanoid:GetAttribute('Stunned') > 0 or Humanoid:GetAttribute('Blocking') ~= false then return end
	if input.KeyCode == Enum.KeyCode.Q and CD ~= true then
		local animationToPlay
		CD = true
		
		task.delay(2.8, function()
			direction = nil
			CD = false
		end)
		
		local button = "S"
		
		if UIS:IsKeyDown(Enum.KeyCode.W) then
			button = "W"
			direction = game.Workspace.CurrentCamera.CFrame.LookVector
		end
		if UIS:IsKeyDown(Enum.KeyCode.S) then
			button = "S"
			direction = -(game.Workspace.CurrentCamera.CFrame.LookVector)
		elseif UIS:IsKeyDown(Enum.KeyCode.A) and not UIS:IsKeyDown(Enum.KeyCode.W) then
			button = "A"
			direction = -(game.Workspace.CurrentCamera.CFrame.RightVector)
		elseif UIS:IsKeyDown(Enum.KeyCode.D) and not UIS:IsKeyDown(Enum.KeyCode.W) then
			button = "D"
			direction = game.Workspace.CurrentCamera.CFrame.RightVector
		end
		
		if direction == nil or not direction then
			animationToPlay = animations['S']
			direction = -(game.Workspace.CurrentCamera.CFrame.LookVector)
		else
			animationToPlay = animations[button]
		end
		
		animationToPlay.Priority = Enum.AnimationPriority.Movement
		
		local connection
		
		connection = animationToPlay.Ended:Connect(function()
			print('Ended okok', animationToPlay.Length)
			connection:Disconnect()
		end)
		print('started ok ok')
		task.delay(animationToPlay.Length, function()
			print('HEllo')
		end)
		animationToPlay:Play(0, 8)
		
		dashEvent:FireServer(direction)
		
		repeat task.wait() until Humanoid:GetAttribute('Dashing') == true
		
		local directionToLook = game.Workspace.CurrentCamera.CFrame.LookVector
		directionToLook = Vector3.new(directionToLook.X, 0, directionToLook.Z)
		
		local lookAt = HRP.Position + (directionToLook * 10000)
		HRP.CFrame = CFrame.new(HRP.Position, lookAt)
	end
end)