Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I choose from a table of animations without having to load it more than once?

Asked by 3 years ago

In my game, I have melee weapons that have different swing animations, and they'll be played randomly when you swing, it adds some variety. I've made a working system for this already, but if you use the animation enough you get a "Animation limit for this animator", or whatever kind of error. Is there a way I could play these animations without loading them more than once?

Here's my current code:

local animations = {
    SWING1 = character.Humanoid:LoadAnimation(script.Swing1),
    SWING2 = character.Humanoid:LoadAnimation(script.Swing2),
    SWING3 = character.Humanoid:LoadAnimation(script.Swing3),
}

local swings = {
    animations.SWING1,
    animations.SWING2,
    animations.SWING3
}

mouse.Button1Down:Connect(function()
    if states.Holding == true and states.Swinging == false and states.Blocking == false then
        states.Swinging = true
        local choices = math.random(1,#swings)
        local swing = swings[choices]
        swing:Play()

        swing.Stopped:Connect(function()
            states.Swinging = false
        end)
    end
end)

Answer this question