Okay so I found a solution to this, however it might not be one for a lot of you guys (I used Promise.lua)
--// My Util Module
local myUtil = {}
local function loadAnimation(hum, anim)
return Promise.new(function(resolve, reject)
local animTrack;
local success, output = pcall(function()
animTrack = hum:LoadAnimation(anim)
end)
if not success then
reject()
else
resolve(animTrack)
end
end)
end
function myUtil:fetchAnimTrack(hum,anim)
return Promise.retryWithDelay(
loadAnimation, 5, 1,
hum, anim
):expect()
end
return myUtil
This function safely loads any AnimationTracks and returns them.
This is the solution, thanks! I hope the post author marks your answer. What I did was I made sure to parent my npc to workspace before loading animations!
Wanted to add my tuppence while this is still considered current.
I have found it necessary to wait a small time after player.CharacterAdded:Connect(onCharacterAdded) fires.
I don’t actually call wait or task.wait, which is generally frowned upon, not that would stop me. Instead I add accessories (just my hat) which seems to impart all the delay I need. Here are my timings:
23:30:54.818 too soon to `animator:LoadAnimation(animation)`
23:30:55.114 1772336109 Enum.AccessoryType.Hat
23:30:55.428 not too soon to `animator:LoadAnimation(animation)`
So yeah, I’m effectively waiting some arbitrary time of about 0.5s, which is bad practice, but it works so why complain?
The elaborate solutions above look nice, but there is nothing specifically to wait for, in either case (both too soon and not too soon):
print(player.Character.Humanoid.Parent.Parent)
returned nil. Which I don’t understand because:
player.Character.Humanoid.Parent.Parent == player.Character.Parent == player
Nothing is impossible, or completely broken, my last answer got me thinking. We do have something to wait for; the success of the call itself.
In lua we handle exceptions using pcall. The canonical solution is therefore:
function safelyLoadTrack(animator: Animator, animation: Animation): AnimationTrack
local success, errorOrData
repeat
success, errorOrData = pcall(function()
return animator:LoadAnimation(animation)
end)
if not success then
warn(errorOrData) -- We're calling it too early but ideally we'd check that with this error message, which we can at least preserve verbatim.
task.wait(0.2)
end
until success
return errorOrData
end
A word of caution on exception handling, don’t ignore errors. Ideally we’d test the errorOrData message is what we expect, and not something pertaining to a non-existant, or bad, animation, or the servers being down.
The error message I expect is:
Cannot load the AnimationClipProvider Service.
but that isn’t formally specified nor guaranteed not to change with future updates.
for me personally the fix wasnt any waits or nothing it was simply the fact i played 2 same animations at the same time that caused the error for me, i had an ancestry changed event connected to an instance that was parented to the character, which after its deleted, plays an animation, i also had a play animation on respawn, since my respawn time was low it was pretty much instant so both (same animations) tried to play vs each other giving me the error, after adding a health>0 check in my ancestry event the error is gone maybe someone has this exact problem if so theres ur fix
This Module Script can probably fix all the problems and its pretty self explanatory on how to use it, but make sure that once your character dies, you reload the animations or else it wont work because it loads it onto the current animator, which if the character dies, is destroyed
--〔 Services 〕--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
--〔 Variables 〕--
local AnimationHandler = {
["LoadedAnimations"] = {};
}
local AnimationsFolder = ReplicatedStorage.Assets.Animations
--〔 Functions 〕--
function FireHostWarning()
if not RunService:IsClient() then
warn("This aspect of AnimationHandler cannot be utilized by the Server.")
end
end
function FireValidityWarning(Input)
local Debounce = false
if typeof(Input) ~= "string" then
warn("Animation Names must be in string format.")
return
end
for Index, Animation in ipairs(AnimationsFolder:GetDescendants()) do
if Animation:IsA("Animation") then
if Animation.Name == Input then
Debounce = true
break
end
end
end
if not Debounce then
warn("'"..Input.."' is not a valid Animation.")
end
end
--〔 Module Functions 〕--
function AnimationHandler:LoadAnimations(Player)
if not RunService:IsClient() then FireHostWarning() return end
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:FindFirstChildOfClass("Animator") or Humanoid
table.clear(AnimationHandler.LoadedAnimations)
for Index, Animation in ipairs(AnimationsFolder:GetDescendants()) do
if Animation:IsA("Animation") then
AnimationHandler.LoadedAnimations[Animation.Name] = Animator:LoadAnimation(Animation)
end
end
end
AnimationHandler["PlayAnimation"] = function(Animation, Properties)
if not RunService:IsClient() then FireHostWarning() return end
if typeof(Animation) ~= "string" then FireValidityWarning(Animation) return end
FireValidityWarning(Animation)
local Animation = AnimationHandler.LoadedAnimations[Animation]
local AdjustSpeed = Properties and Properties.AdjustSpeed or 1
local Weight = Properties and Properties.Weight or 1
local FadeIn = Properties and Properties.FadeIn or 0
local FadeOut = Properties and Properties.FadeOut or 0
local Looped = Properties and Properties.Looped or Animation.Looped
local Duration = Properties and Properties.Duration or false
Animation:Play(FadeIn, Weight, AdjustSpeed)
Animation.Looped = Looped
if Duration then
task.delay(Duration, function()
Animation:Stop(FadeOut)
end)
else
if not Looped then
task.delay(Animation.Length, function()
Animation:Stop(FadeOut)
end)
end
end
end
AnimationHandler["StopAnimation"] = function(Animation, Properties)
if not RunService:IsClient() then FireHostWarning() return end
if typeof(Animation) ~= "string" then FireValidityWarning(Animation) return end
FireValidityWarning(Animation)
local Animation = AnimationHandler.LoadedAnimations[Animation]
local FadeOut = Properties and Properties.FadeOut or 0
if Animation.IsPlaying then
Animation:Stop(FadeOut)
end
end
AnimationHandler["StopAllAnimations"] = function(Properties)
if not RunService:IsClient() then FireHostWarning() return end
local FadeOut = Properties and Properties.FadeOut or 0
for Index, AnimationTrack in pairs(AnimationHandler.LoadedAnimations) do
if AnimationTrack.IsPlaying then
AnimationTrack:Stop(FadeOut)
end
end
end
--〔 Return 〕--
return AnimationHandler
Totally a year later, tried this out and seems to get hit with the ClipProvider Error in the this module. Crazy right? Even with Promise implementation its like, “oh yeah im loaded no im not”
FYI previously using deprecated :LoadAnimation due to the fact using an animator is giving out another random error
This issue is getting out of hand for me. No matter how long I have my game wait to load animations for the player it will still fail to load. I have had it wait 1 second, 5, 10, even 20 seconds and it still fails. I’ve also even had it wait for the player to be a descendant of workspace, and then delay it further after it, yet it doesn’t work. The simple add a task.wait(1) use to work but now it just won’t work at all. What’s even worse now is that now the whole screen just goes black and you can’t see anything whenever this issue occurs (There is no GUI covering the screen and the camera CFrame is not at a weird position so I have no clue what is happening)
I hope they figure something out and fix this issue as soon as they can because it is just painful to work with.
Try loading it into the Dummy’s animator. and if this is happening with players
(strange bug) use
local plr = plr.CharacterAdded:Wait()
INSTEAD OF
local plr = plr.Character or plr.CharacterAdded:Wait()
I don’t know why this works, but it does…
I dunno why it happens and has been happening so recently but its still weird as hell, possibly an engine bug
After turning off ‘characterautoload’ and spawning a character using ‘Player:loadcharacter’, this error starts spamming my console. The error only appears when I spawn the character using ‘Player:loadcharacter’ after the character has died. This issue does not occur on the first spawn.
NVM my bad, add debouce to the killbrick solve the issue
This bug seems to still be around. What is even worse is that there is nothing you can do expect add an arbitrary task.wait(1) before loading the animation. If you use a pcall, it doesnt matter as no matter how many times you retry it never works after the first error.
What I do, is a bit cheap, is just to wait until the character has fully loaded. Then I add :WaitForChild()'s, then I load the animation on the animator.
Usually, if im using Animation.Length, then ill use this simple piece of code:
repeat task.wait() until Animation.Length > 0.05
sure,this wont work if your animation length is under 0.05 seconds, but i doubt you would be making an animation that fast.
You could try to add the wait at the first line of code like wait(1) in order to wait for the animation service to reload once the player died or something. It worked for me.
From my understanding, the issue relies in the animation not playing because the player isn’t loaded in yet.
The simplest solution for that would be the following:
local player = -- Insert player here.
repeat task.wait() until player.Character
repeat task.wait() until player:HasAppearanceLoaded()
The first loop makes sure that the character is actually created.
The second loop makes sure the character is fully loaded in. (I believe using HasAppearanceLoaded() without a character being added yet results in an error. Correct me if I’m wrong here.)
Using generic wait() is not ideal.
Hope this helps!