How do I fix the "Cannot load the AnimationClipProvider Service" error when the player respawns?

Hello! I’ve made a stick weapon for my game but ran into a problem upon dying and respawning. The script works perfectly when first spawning in, but once you die and respawn the script fails and I get this error.


I tried reading up why it is caused and I believe it is caused because the animation loads before the player loads, but I am not 100% sure. If that is the issue, I am not sure how to properly add a wait to fix the issue as everything I try gives back an infinite yield error.
Here is the code (I tried to only include the code relevant to the issue)

local Stick = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Animator = Character:WaitForChild("Humanoid"):WaitForChild("Animator")

local AnimId = 11256394970
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://"..AnimId

local AnimId2 = 11230257521
local Anim2 = Instance.new("Animation")
Anim2.AnimationId = "rbxassetid://"..AnimId2

local PlayAnim1 = Animator:LoadAnimation(Anim) --- issue starts here
local PlayAnim2 = Animator:LoadAnimation(Anim2)

Any help on how to fix this issue would be greatly appreciated!

Look at this

try to load the animations before doing the action, also save the variable so that the animations are not created constantly.

1 Like