Animation didn't load

I tried to make animation for my tool but the animation didnt load.Is there any way to fix this?

Here the script that i made to load the animation

local player=game:GetService("Players").LocalPlayer
local  char=player.Character or player.CharacterAdded:Wait()
local h=char:WaitForChild("Humanoid")
local anim=script.Animation
local  animtrack=h:LoadAnimation(anim)

script.Parent.Equipped:Connect(function()
	animtrack:Play()
end)

Did you get an error when running the script?

If there’s no errors popping up, this may be happening because Roblox is not having enough time to fetch your animation from their website.

You can easily prevent this by using Content Provider. This allows you to preload animations or any assets that have to be fetched from the Roblox website, to make sure they always run/appear to the player.

You should add a few lines to your code, should look something like this.

local player=game:GetService("Players").LocalPlayer
local  char=player.Character or player.CharacterAdded:Wait()
local h=char:WaitForChild("Humanoid")
local anim=script.Animation

local contentProvider = game:GetService("ContentProvider")
contentProvider:PreloadAsync({anim.AnimationId})

local  animtrack=h:LoadAnimation(anim)

script.Parent.Equipped:Connect(function()
	animtrack:Play()
end)

A good reminder that Content Provider yields your script, which may cause delays on the equipping animation, it’s best to have an external script handling Content Provider and making sure all assets have been fetched.

You should only face this issue once, when equipping for the first time, for your next attempts it should work just fine, if not, make sure if your code is running properly.

2 Likes

There was no error when running the scriptm

image

i suggest you to use

local hum = script.Parent.Parent:WaitForChild("Humanoid")

local anim = hum:LoadAnimation(script:FindFirstChildOfClass("Animation"))

anim:Play()
1 Like

Pardon me, I forgot the brackets. Content Provider only takes arrays, so you need to wrap all the IDs with brackets to turn it into an array.

Replace it with this line.

contentProvider:PreloadAsync({anim.AnimationId})
1 Like

Another potential issue may be the tool rather than the script. If the tool doesn’t have a handle make sure you uncheck RequiresHandle or the script wont run. I ran your original code and it worked for me, I just had to uncheck the box.

1 Like

Thanks.The animation is now loaded when i equipped the tool :slight_smile:

1 Like