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())
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")})
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.
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?
'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()
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.
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.