So I have a local script called AnimationHandler that obviously handles the animations. And the problem is when a player just spawned, it takes a few seconds to load all the animations into the humanoid and thats really annoying for some players. I tried removing the repeat until, but then it just doesn’t load the animations
repeat task.wait()
for i, v in pairs(Tool.Animations:GetDescendants()) do
if v:IsA("Animation") and v.Name == "AttackRightShieldless" then
AttackRightShieldless = animator:LoadAnimation(v)
table.insert(allAnims, AttackRightShieldless)
table.insert(possibleAttackAnimations, AttackRightShieldless)
AttackRightShieldless:SetAttribute("Direction", "Right")
elseif v:IsA("Animation") and v.Name == "AttackLeftShieldless" then
AttackLeftShieldless = animator:LoadAnimation(v)
table.insert(allAnims, AttackLeftShieldless)
table.insert(possibleAttackAnimations, AttackLeftShieldless)
AttackLeftShieldless:SetAttribute("Direction", "Left")
elseif v:IsA("Animation") and v.Name == "AttackOverheadShieldless" then
AttackOverheadShieldless = animator:LoadAnimation(v)
table.insert(allAnims, AttackOverheadShieldless)
table.insert(possibleAttackAnimations, AttackOverheadShieldless)
AttackOverheadShieldless:SetAttribute("Direction", "Up")
elseif v:IsA("Animation") and v.Name == "AttackStabShieldless" then
AttackStabShieldless = animator:LoadAnimation(v)
table.insert(allAnims, AttackStabShieldless)
table.insert(possibleAttackAnimations, AttackStabShieldless)
AttackStabShieldless:SetAttribute("Direction", "Bottom")
elseif v:IsA("Animation") and v.Name == "Equip" then
Equip = animator:LoadAnimation(v)
table.insert(allAnims, Equip)
elseif v:IsA("Animation") and v.Name == "Block" then
Block = animator:LoadAnimation(v)
table.insert(allAnims, Block)
elseif v:IsA("Animation") and v.Name == "Idle" then
Idle = animator:LoadAnimation(v)
table.insert(allAnims, Idle)
end
end
until workspace:IsAncestorOf(character)
I guess there should be a different method to handle the animations loading, but I have no idea of how would I make it
Try Preloading the Animations with ContentProvider
local CProvider = game:GetService("ContentProvider")
for _,i in pairs(game:GetDescendants()) do
if i:IsA("Animation") then
CProvider:PreloadAsync(i)
end
end)
Alright now it works, but how do I load it into a humanoid now? Do I put it into the function itself like in my original script? I have never used ContentProvider
Yes, use StarterPlayerScripts, not StarterGui or StarterCharacterScripts. StarterGui or StarterCharacterScripts will clear itself, so scripts will rerun and load again, adding onto unnecessary performance. StarterPlayerScripts only run once and don’t rerun or load again.
Content Provider simply replicates those items first.
You can load an animation by doing Humanoid:LoadAnimation(ANIMATION_HERE). The humanoid being the desired humanoid. After you load the animation you can do :Play() to start it.