How to add 2 animation in a sword

i want to add 2 animation in my sword , like the first click it will play the first animation the second click it will play the second animation , keep repeating

2 Likes

Hey,

there is few ways of doing this, I’ll show you one.

You will have variable of which animation is player (1 or 2)

if it is 1 then you play 2 and change variable to 2,
if it is 2 then you play 1 and change variable to 1.

2 Likes

You should learn some starter scripting first before look into stuff like those

First you make a variable, then you can make a function when the player actives it, it will go through arguments, for example the variable is 1 for anim1 and 2 for anim2, the variable will be 1 firstly. If it’s 1 then it will run animation1, then make it turns the var to 2. Then plr actives the funciton again, now var is 2 then it runs anim2 and you make it changes the var to 1. So it repeats

1 Like

Do you already have a script for the sword?

local anim = 2

function playAnim()
      if anim == 1 then
         anim = 2
         local swordAnim = Humanoid:LoadAnimation("animation 2 here") 
      else
         anim = 1
         local swordAnim = Humanoid:LoadAnimation("animation 1 here")  
      end
end
4 Likes

You can use math.random() like this:

local number = math.random(1,2)

function swing()
       --- Just like Sougood code but without setting Anim value
end
1 Like

Also is the sword a tool or is it attached to the character?
Because I can help if it’s the latter.

Please try doing this yourself before posting a thread to the forums. This is not a do-my-work category, it’s for help after you have made an attempt or have some semblance of where you’re going but not fully how to execute it. Refer to our category guidelines for more information on how to use this category and the expectations upheld for it.

There are already many resources you can reference that have animations in the tools, so I’m sure this isn’t a problem you can’t solve on your own or at least have an idea of where you’re going. If you don’t have that, it’s strongly recommended you do research first, whether on expanding your fundamental programming knowledge or on what seems appropriate to be using in this scenario.

Some obvious searches to be making are for the Tool and Animation class on the Developer Hub.

2 Likes