Multiple animations on a click

How do i make multiple animations on 1 click?

What i want to achieve

Making a sword combat system, and i dont know how to make mutiple animations on a click.

What the clicks do

First Click: Plays a animation
Second Click: Plays the second animation
Third Click: Plays the third animation
Fourth Click: Plays the fourth animation

Please keep in mind i am NOT asking for free code.

1 Like

You could technically use a number variable that adds up by one per click. Depending on the number, you play a specific animation. When it reaches the number 4, you can just set it to it’s starting number.

1 Like

Can you give me a example? ```

1 Like

I could give some code, but I’m not at home right now. Typing on a phone haha.

You can send it later if you can.

1 Like

I will just say what @Downrest means: just an example

local number = 0

button.MouseButton1Click:Connect(function()
    number = number + 1
     
    if number == 1 then
        animation1:Play()
    elseif number == 2 then
        animation2:Play()
    elseif number == 2 then
        animation3:Play()
    elseif number == 4 then
        animation4:Play()
        number = 0 -- Restarts from the beginning.
    end
end)

If you want more easier but complex measures:

local number = 0

local audioDictionary = {
    [1] = 0, - audio ID of anim 1
    [2] = 0, - audio ID of anim 2
    [3] = 0, - audio ID of anim 3
    [4] = 0, - audio ID of anim 4
}

button.MouseButton1Click:Connect(function()
    number = number + 1
    anim.AnimationId = "rbxassetid://"..audioDictionary[number]
    anim:Play()
    
    if number == 4 then
        number = 0
    end
end)
1 Like

This happened.

Did you replace the fake animation1 with your animation?

Also can I see the whole script?

Hold up, why is it using anim.SoundId?

Oh, my bad. It’s suppose to be an animation. Just fixed it

Oh and, you can’t play an Animation. You would have to do :LoadAnimation() on the an Animator first.

1 Like

Yeah I knew that but for the sake of my time and just for examples.

1 Like

1 Like

Oh so you want to click it on a tool. That’s easy, just do this:

local number = 0

script.Parent.Activated:Connect(function()
    number = number + 1
     
    if number == 1 then
        script.A1:Play()
    elseif number == 2 then
        script.A2:Play()
    elseif number == 2 then
        script.A3:Play()
    elseif number == 4 then
        script.A4:Play()
        number = 0 -- Restarts from the beginning.
    end
end)

I saw that you were using my second method, but that only works when you have 1 animation.

I’m feeling like this statement was false, but to load an animation:

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

local loadAnim = character.Humanoid.Animator:LoadAnimation(ANIMNAME)
loadAnim:Play()

put this in each if statement.

--// Services
local Players = game:GetService("Players")

--// Player Instances
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

--// Tool
local Tool = -- Define Tool Here

--// Tables
local Animations = {  -- You can add more and it will always play the next animation
   124124124, -- 1 
   124124124, -- 2 
   124124124, -- 3
   124124124, -- 4
}

local loadedAnimations = {}

--// Functions
local function loadAllAnimations()
   local Humanoid = Character:FindFirstChild("Humanoid") 
   if not Humanoid then return warn("No humanoid") end

   for Index, ID in ipairs(Animations) do
      local animationInstance = Instance.new("Animation")
      animationInstance.AnimationId = "rbxassetid://"..ID
      local loadedAnimation = Humanoid:LoadAnimation(animationInstance)
      table.insert(loadAnimations, loadedAnimation)
   end
end)
loadAllAnimations()

--// Connection
local timesPressed = 1
Tool.Activated:Connect(function()
   loadedAnimation[timesPressed]:Play()
   timesPressed += 1
   if timesPressed >= #Animations then timesPressed = 0 end
end)

Hope this helps, just wrote this so no clue if it will work but you can try it out. Though make sure it fits your game by changing tool location and animations IDs

Apparently this topic is dead, but thanks1

@TheDCraft This script wont work :frowning: