Content provider not loading an animation

Pretty straight forward, i have these lines of code

local ContentProvier = game:GetService("ContentProvider")
ContentProvier:PreloadAsync({Config:WaitForChild("HurtAnim").AnimationId})

And when i run it, the animation doesn’t load, and it doesn’t allow the rest of the script to run. How do i fix this? Help would be appreciated. I’m also not getting any errors. Even if i use AnimTrack = Humanoid:LoadAnimation(Animation) it still doesn’t “load” then animation. (The animation only appears to load properly a second after i use AnimTrack:Play())

2 Likes

Read the documentation page of the methods you’re working with first before posting threads. The explanation is right on the page. PreloadAsync only accepts a table of objects. First paragraph:

This function takes an array of Instances as a parameter and yields until all of assets associated with those instances have loaded.

Simply remove .AnimationId and you should be good to go.

1 Like

I did that, and it allowed the rest of the code to run, but didn’t load the animation in. As you can see the animation does not play straight away (it has to load in first, and it didn’t) And no, this is not lag. I’m testing this in studio

local ContentProvier = game:GetService("ContentProvider")
ContentProvier:PreloadAsync({Config:WaitForChild("HurtAnim")})
1 Like

It’s unrelated to the preloading of the animation asset. I suspect that you’re calling LoadAnimation as in when the sword hits the dummy and then proceed to play that loaded animation. The thing about LoadAnimation is that it actually has to grab animation data from the animation object and then cache it on the Humanoid so that it is ready to play.

If you use LoadAnimation earlier in your script (such as somewhere around the top) and then only call play animation when the dummy should be injured rather than both loading and playing the animation when it is injured, that should resolve your problem.

I’m making assumptions here because I don’t know how you’re handling the playback of the animation.

1 Like

I loaded the animation way before playing (when the NPC spawned, and still didn’t load in.) even if i use AnimTrack = Humanoid:LoadAnimation(Animation) again, it still doesn’t load in the animation. The animation only starts loading once it plays

and heres the entire code:

Character = script.Parent

Humanoid = Character:WaitForChild("Humanoid")

Config = Character:WaitForChild("Config")
Animation = Config:WaitForChild("HurtAnim")

AnimTrack = Humanoid:LoadAnimation(Animation)

OldHealth = Humanoid.Health

Humanoid.HealthChanged:Connect(function()
    if Humanoid.Health < OldHealth and Humanoid.Health > 0 then -- Humanoid has been damaged
        AnimTrack:Play()
    end
    OldHealth = Humanoid.Health
end)

Oh? That’s rather strange, should be playing immediately. I have one final question for you before I’ve exhausted my means of being able to help you: where is the script that uses ContentProvider?

1 Like

game > workspace > NPC > Script (a separate script)

:LoadAnimation() might be bugged too

's probably it. ContentProvider’s PreloadAsync only works in a LocalScript. Preload this from the client instead, preferably under ReplicatedFirst or in whatever client initialisation scripts you may have.

You are capable of preloading the animation data if you don’t want to directly preload the object in the NPC. Somewhat expensive to do, but you create proxy objects and load those, then get rid of them. Here’s an example using only one id.

local ContentProvider = game:GetService("ContentProvider")

local animId = 0

local animForLoad = Instance.new("Animation")
animForLoad.AnimationId = "rbxassetid://" .. animId

ContentProvider:PreloadAsync({animForLoad})

animForLoad:Destroy()

That seemed to do nothing. the animation only appears to load (approximately 0.2 - 5 seconds after) with Humanoid:PlayAnim()

:pensive:

I’m out of ways then. Sorry that my methods haven’t been able to be of much help. I typically don’t experience animation issues so I’m applying what I know from my situations.

Hopefully someone else will be able to come along and help you resolve your issue, or you may end up finding a solution toying with the implementation while waiting for a response.

1 Like

Thanks for trying to help. I appreciate it!

Also should i consider this issue a bug?

i mean LoadAnimation() and ContentProvider aren’t really doing their job

No, it’s (defintiely) not a bug because nothing is actually broken. Has to do with either the implementation or the way in which the client downloads assets. There is a way to resolve this, I know it.

1 Like