Why do my viewmodel animations stop working randomly

i followed a tutorial from 2021 to make an fps game so the problem may just be the sort of outdated code but idk

local gun = script.Parent
-- services
local runService = game:GetService("RunService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
-- objects
local viewmodel = replicatedStorage:WaitForChild("MainGame"):WaitForChild("Guns"):WaitForChild("AK-47"):Clone()
local camera = workspace.CurrentCamera
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local h = character:WaitForChild("Humanoid") or character:FindFirstChild("Humanoid")
local mouse = player:GetMouse()
viewmodel.Parent = replicatedStorage.UnequippedGuns
-- modules
local config = require(viewmodel:WaitForChild("Config"))
-- main code
local cf = CFrame.new()

local maxBullets = workspace.maxBullets
local bulletsUsed = workspace.bulletsUsed

local sinSpeed = 8
local sinSize = 6 
local cosSpeed = 12
local cosSize = 8
local recoilSpeed = 10
local recoilSize = .5

local equipConnection

local shoot_CoolDown = false
local isHolding = false
local isEquipped = false

local animations = {
	["Hold"] = viewmodel.AnimationController.Animator:LoadAnimation(viewmodel.Animations.Hold);
	["Shoot"] = viewmodel.AnimationController.Animator:LoadAnimation(viewmodel.Animations.Shoot)
}

if h ~= nil then
	animations["CharacterHold"] = h:LoadAnimation(viewmodel.CharacterAnimations.Hold);
end

cf = config.Offset_From_Camera

function positionModel()
	if player.character then
		viewmodel:SetPrimaryPartCFrame(camera.CFrame*cf)
		local sin = math.sin(time() * sinSpeed)/ sinSize
		local cos = math.cos(time()* cosSpeed)/ cosSize
		if player.character.Humanoid.MoveDirection.Magnitude > 0 then
			cf = cf:Lerp(CFrame.new(config.Offset_From_Camera.X+sin, config.Offset_From_Camera.Y+cos, config.Offset_From_Camera.Z),.1)
		else
			cf = cf:Lerp(config.Offset_From_Camera,.2)
		end
	end
end

function shoot(target)
	if not shoot_CoolDown then
		shoot_CoolDown = true
		animations["Shoot"]:Play()
		if player.Character:FindFirstChild(script.Parent.Name)then
			local sin = math.sin(tick() * recoilSpeed)/ recoilSize
			cf = cf:Lerp(CFrame.new(config.Offset_From_Camera.X, config.Offset_From_Camera.Y, config.Offset_From_Camera.Z+sin),.1)
			viewmodel.shootSound:Play()
		end	
		if target ~= nil then
			if target.Parent:FindFirstChild("Humanoid") then
				replicatedStorage["MainGame"]["remoteEvents"]["shootEvent"]:FireServer(mouse.Target, gun.Name)
			end
			
		end
		wait(config.Cooldown_Between_Clicks)
		shoot_CoolDown = false
	end
end

gun.Activated:Connect(function()
	if config.isAutomatic == false then
		shoot(mouse.Target)
	end
end)

mouse.Button1Down:Connect(function()
	if config.isAutomatic == true then
		isHolding = true
	end
end)

mouse.Button1Up:Connect(function()
	if config.isAutomatic == true then
		isHolding = false
	end
end)

local function equip()
	if not gun and viewmodel then return end
	for _, part in pairs(gun:GetChildren()) do
		if part:IsA("BasePart") or part:IsA("UnionOperation") then
			part.Transparency = 1
		end
	end
	viewmodel.Parent = camera
	animations["Hold"]:Play()
	if h ~= nil then
		animations["CharacterHold"]:Play()
	end

	
	equipConnection = runService.RenderStepped:Connect(function()
		if player.character.Humanoid.Health > 0 then
			positionModel()
		end 
	end)
end
	
local function unequipped()
	if not gun then return end
	equipConnection:Disconnect()
	viewmodel.Parent = replicatedStorage.UnequippedGuns
	if h ~= nil then
		animations["CharacterHold"]:Stop()
	end
end

gun.Equipped:Connect(function()
	mouse.Icon = "http://www.roblox.com/asset/?id=9524023207"
	isEquipped = true
	equip()
end)

gun.Unequipped:Connect(function()
	mouse.Icon = ""
	isEquipped = false
	unequipped()
end)

runService.RenderStepped:Connect(function()
	if isHolding == true and isEquipped == true then
		shoot(mouse.Target)
	end
end)

that is basically the same code used for all of my guns

pls help