Cannot load the AnimationClipProvider Service error

  1. What do you want to achieve?
    I want player to have a animation when they are holding a gun.

  2. What is the issue?
    When I reset my character it does not work and the “Cannot load the AnimationClipProvider Service” error pops up

this is my script, the error is at line:
[“CharacterHOLD”] = char:WaitForChild(“Humanoid”):LoadAnimation(viewModel.CharacterAnimations.Hold)

local gun = script.Parent
local runServce = game:GetService("RunService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local viewModel = replicatedStorage:WaitForChild("MainGame"):WaitForChild("Guns"):WaitForChild("Pistol"):Clone()
local camera = workspace.CurrentCamera
local plr = players.LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
viewModel.Parent = replicatedStorage.UnequippedGuns

local config = require(viewModel:WaitForChild("Config"))

local cf = CFrame.new()

local equipConnection
local walkAnimationSpeed = 5
local walkAnimationSize = 4

local recoilSpeed = 10
local recoilSize = 4

local shoot_cd = false
local isHolding = false
local isEquipped = false

local animations = {
	["Hold"] = viewModel.AnimationController.Animator:LoadAnimation(viewModel.Animations.Hold),
	["CharacterHOLD"] = char:WaitForChild("Humanoid"):LoadAnimation(viewModel.CharacterAnimations.Hold)
}

function positionModel()
	local Humanoid = char:WaitForChild("Humanoid")
	if Humanoid then
		if Humanoid.MoveDirection.Magnitude > 0 then
			cf = camera.CFrame*config.Offset_From_Camera
		else
			cf = camera.CFrame*config.Offset_From_Camera
		end
		viewModel:SetPrimaryPartCFrame(cf)
	end
end

function shoot(target)
	if not shoot_cd then
		shoot_cd = true
		if plr.Character:FindFirstChild(script.Parent.Name)  then
			local sin = math.sin(time() * recoilSpeed)/recoilSize
			cf =cf:Lerp(CFrame.new(config.Offset_From_CameraX, config.Offset_From_Camera.Y, config.Offset_From_Camera.Z+sin),.2)
			viewModel.Shoot:Play()
		end
			if target.Parent:FindFirstChild("Humanoid") then
				replicatedStorage.MainGame.Remotes.Shoot:FireServer(mouse.Target, gun.Name)
			end
		wait(config.CoolDown_Each_Click)
		shoot_cd = 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()
	animations["CharacterHOLD"]:Play()
	equipConnection = runServce.RenderStepped:Connect(function()
		positionModel()
	end)
end

local function unequip()
	if not gun then return end
	equipConnection:Disconnect()
	viewModel.Parent = replicatedStorage.UnequippedGuns
	animations["CharacterHOLD"]:Stop()
end

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

gun.Unequipped:Connect(function()
	isEquipped = false
	unequip()
	mouse.Icon = "rbxasset://SystemCursors/Arrow"
end)

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

Please research your problem before making a duplicate DevForum post.

make sure that the viewmodel’s parent is workspace before loading the animation.

2 Likes

for tools
call the variables for the humanoid and character again before loading the animations
it happens because the game is trying to load animations for the old character which is parented to nil
so call the variable in for instance the equipped function, which will give the script the new character to load the animations to

gun.Equipped:Connect(function()
	char = plr.Character 
        humanoid = char:WaitForChild("Humanoid")
        animations = {
	     ["Hold"] = viewModel.AnimationController.Animator:LoadAnimation(viewModel.Animations.Hold),
	     ["CharacterHOLD"] = char:WaitForChild("Humanoid"):LoadAnimation(viewModel.CharacterAnimations.Hold)
        }
        mouse.Icon = "http://www.roblox.com/asset?id=9947945465"
	isEquipped = true
	equip()
end)