Get loaded animations from a humanoid

I am trying to make an animation loader for my gun framework but i have an issue with getting the animations after they have been loaded.

Here is my animation loader:

local function loadGunAnimations()
    while not GunHumanoid:IsDescendantOf(game) do
        GunHumanoid.AncestryChanged:Wait()
    end
    if not GunHumanoid:IsDescendantOf(game) then
        return
    end
    for _, Animation in pairs(GunAnimationsFolder:GetDescendants()) do
        if Animation:IsA("Animation") then
            GunHumanoid:LoadAnimation(Animation)
        end
    end
end
1 Like

What you can do is store the loaded animations into a table:

local HumanoidAnimations = {}

local function loadGunAnimations()
    while not GunHumanoid:IsDescendantOf(game) do
        GunHumanoid.AncestryChanged:Wait()
    end
    if not GunHumanoid:IsDescendantOf(game) then
        return
    end
    for _, Animation in pairs(GunAnimationsFolder:GetDescendants()) do
        if Animation:IsA("Animation") then
            HumanoidAnimations[Animation.Name] = GunHumanoid:LoadAnimation(Animation)
        end
    end
end

You can then play the animation like so:

HumanoidAnimations[AnimationName]:Play()

Or if you wish you can use the object as the index.

6 Likes

Hey there,

Humanoid:GetPlayingAnimationTracks() for your help

3 Likes

Ah, i see. Thank you for this answer. And to you @GoldyyDev, Does that work if the animation is not playing?

1 Like

That only gets the Playing animation tracks I believe he wants to access all the loaded animations.

No. If the animation is not running it will not play. getting all the animations may be impossible but I have to investigate.

1 Like

i’m trying to find a way to get all animations loaded inside of humanoid
:C

There is no method available for doing this, you need to manually track that yourself. If you’re having trouble predictably determining what animations play on a Humanoid, you can use AnimationPlayed and then log the playing AnimationTrack and its id in a table or dictionary someplace.

2 Likes

ty, i read that event a few days and i get a way for my problem, save every animation inside a table and changed the animator parent to the another humanoid and use the table to play the animations

1 Like