If Character resets I get this error "Cannot load the AnimationClipProvider Service"

As the title said I am running into an issue with the “Cannot load the AnimationClipProvider Service”
after the player has died or resets. However if the player never dies/resets the animations play as expected.

This script is running in StarterPlayerScripts as a LocalScript

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local function playAnimation(animationId)
	if not character and not humanoid then return end
	
	local animator = humanoid:FindFirstChild("Animator")
	if not animator then
		warn("⚠️ No Animator found! Creating one...")
		animator = Instance.new("Animator")
		animator.Parent = humanoid
	end
	
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://" .. tostring(animationId)
	
	local animationTrack = animator:LoadAnimation(animation) --This is the line the error is happening on. 
	animationTrack:Play()
	return animationTrack
end


local function stopHoldingAnimation()
	if holdingAnimation then
		holdingAnimation:Stop()
		holdingAnimation = nil --sets to nil if player isn't holding a weapon
	end
end

--The below function plays/stops the animations based if the character has a gun out
local function onWeaponSwitch(...)
	local Gun_Information = {...}
	if #Gun_Information ~= 0 then
		Gun_Name = Gun_Information[1]
		Gun_Stats = Gun_Information[2]
		canShoot = true
		
		print("[DEBUG] Client Equipped Gun: "..Gun_Name)
		Current_Gun = Gun_Name
		Tool = character:FindFirstChild(Gun_Name)

		if Gun_Stats then
			Ammo = Gun_Stats.MaxAmmo
			playHoldingAnimation()
		else
			error("[DEBUG] Gun configurations not found for "..Gun_Name..".")
		end
	else
		Current_Gun = nil
		Gun_Stats = nil
		Ammo = 0
		canShoot = true
		
		stopHoldingAnimation()
	end

	updateMouseCrosshair()
end

I’m not sure if this isn’t the complete script or what cause you never call playAnimation() you call playHoldingAnimation() instead(also not including animationId) and the variable used in stopHoldingAnimation() is never defined or updated so I’d imagine that would be underlined and that function doesn’t do anything either. I’m not sure what is causing the error but if it works before dying then you can just make the script reset on spawn by putting it in starterCharacter instead.

This error occurs when you attempt to load an animation on a rig that is not currently a descendant of the runtime data model (game). This occurs either when the player is still (re)spawning or has died and you have an outdated reference to their rig. In your case, I can see your script does not account for the player’s death as StarterPlayerScripts will not restart your script for you.

The most convenient solution to this problem is:

Moving your script to StarterCharacterScripts. This container will automatically recycle your script on respawn. You can re-define the character as:

-- Local player not necessary
local character = script.Parent
local humanoid = character.Humanoid -- Guaranteed existence
2 Likes

yeah this is only going to get the character once.

If your script is in StarterCharacterScripts it will be cloned into the character each time it spawns. It will also be destroyed when the character is destroyed.

I call the function at the bottom of the script in the if Gun_Stats then statement and just below Ammo = Gun_Stats.MaxAmmo

Thank you for the solution. Also thank you to everyone that helped in giving me possible solutions to my problem

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.