Animation stops half way threw

local userInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://16188791182"
local isplaying = false
local plr = game.Players.LocalPlayer
local replicatedStorage = game.ReplicatedStorage
local fireBlast = replicatedStorage.fireBlast
player.CharacterAdded:Wait()

local ClassicSword = player.Backpack.ClassicSword

local toolEquipped = false

local function onToolEquipped()
	toolEquipped = true
end

local function onToolUnequipped()
	toolEquipped = false
end


local function onKeyPress(input)
	local direction = workspace.CurrentCamera.CFrame.LookVector
	if input.KeyCode == Enum.KeyCode.R then
		if isplaying == false and toolEquipped then
			
			isplaying = true
			local char = plr.Character or plr.CharacterAdded:Wait()
			local humanoid = char:WaitForChild("Humanoid")
			local animplay = humanoid:LoadAnimation(animation)
			animplay:Play()
			animplay.Stopped:Connect(function()
				isplaying = false
			end)
			fireBlast:FireServer(direction)
		end
	end
end

userInputService.InputBegan:Connect(onKeyPress)
ClassicSword.Equipped:Connect(onToolEquipped)
ClassicSword.Unequipped:Connect(onToolUnequipped)

my animation stops half way threw.

You can try loading the animation outside and before the onkeypress function. The code loads the animation every time the key is pressed. This might cause a delay before the animation plays, causing it to not play correctly. This happens because it takes time to load the animation over and over again.