AnimationTrack:Play() Not Working

This issue only occurs on spawn (probably because of something in the character not loading in.

To clarify, here’s my code.

If I wait long enough, it will play almost 100% of the time, but if I don’t wait, it will NOT play almost 100% of the time. Anybody know what’s causing this or how to fix it? The humanoid and animation are loaded in correctly, but when you play it, it doesn’t always play correctly. The animation priority is high enough. Thanks!

2 Likes

You should probably ensure the character has loaded.

An efficient way to do so is by writing the following:

local Char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

(If this is a localscript)

2 Likes

The character exists, so doing this would delay the thread by 0 seconds. As I stated, the Humanoid exists, and is capable of loading an animation. However, this animation track is not able to be played until moments after.

1 Like

Probably because you either delayed the animation in your animating program or you did something weird with your animation frame key binds. Ensure that everything with your program or and frame keybinds is fine before I deep further into this.

1 Like

I think it’s because the animation asset hasn’t finished loading yet so when you call play on the animation track, nothing will actually happen. I dont think there’s a way to bypass this other than waiting a few seconds when the server starts

1 Like

As I stated, the animation is 100% OK, which is why it DOES work when I add a delay.

1 Like

So how long is “safe enough”? Should I just keep looping play on the animation?

1 Like

You can use the content provider service to preload the animation, so that it is downloaded. Then you can play it normally

1 Like

Try adding at the top. Pretty sure this will yield the code for a split second tho

game:GetService(“ContentProvider”):PreloadAsync({self.currentGun.GunIdle})
1 Like

Still doesn’t work. I did it like this:

local anims = {}

for _, weapon in pairs(ServerStorage.Assets.Tools:GetChildren()) do
table.insert(anims, weapon:FindFirstChild(“GunIdle”))
end

ContentProvider:PreloadAsync(anims)

(all of this is before the module is used)

1 Like