Hi well my problem is I got a animation script but i cna only put 1 animation in the sword and i want to add more does anyone knows how to add more then 1 animation to a model like when you click 1 time a animation pop up and when you click again another pop up and then it repeats ill let the scripts i used down here.
FIRST SCRIPT
01 | script.Parent.blade.Touched:connect( function (p) |
02 |
03 | if script.Parent.CanDamage.Value = = true then |
04 |
05 | script.Parent.CanDamage.Value = false |
06 |
07 | p.Parent.Humanoid:TakeDamage( 20 ) |
08 |
09 | end |
10 |
11 | end ) |
SECOND SCRIPT
01 | local CanAttack = true |
02 |
03 |
04 |
05 |
06 |
07 | script.Parent.Activated:connect( function () |
08 |
09 | local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack) |
10 |
11 |
12 |
13 | if CanAttack = = true then |
14 |
15 | attack:Play() |
I use this 2 scripts plz help me i rlly want to add more then 1 animation to my sword
Please bare with me, because this is the first time I'm answering a question.
I thought of it this way.
Use math.random
. This will be perfect if you want to have more than 1 animation, but that will not go in order.
Example of math.random
1 | local number = math.random( 1 , 2 ) |
2 | --the two numbers in the brackets at the end are number ranges. The left number is where it starts at, and the right number is where it ends at (example: (1, 5) would be a number range of 1 to 5). |
3 | if number = = 1 then |
4 | --If the number has chosen 1 then |
5 | print ( "One has been chosen" ) |
6 | elseif number = = 2 then |
7 | --If the number isn't any number other than 2, then |
8 | print ( "Two has been chosen" ) |
9 | end |
Without the comments:
1 | local number = math.random( 1 , 2 ) |
2 | if number = = 1 then |
3 | print ( "One has been chosen" ) |
4 | elseif number = = 2 then |
5 | print ( "Two has been chosen" ) |
6 | end |
There are many other uses for math.random, but let's use it in your situation.
Let's take a look at your script now.
01 | local CanAttack = true |
02 |
03 |
04 |
05 |
06 |
07 | script.Parent.Activated:connect( function () |
08 |
09 | local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack) |
10 |
11 |
12 |
13 | if CanAttack = = true then |
14 |
15 | attack:Play() |
Before adding the math.random part, you need to make a second variable to the second aniimation.
1 | local attack 1 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack 1 ) |
2 | local attack 2 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack 2 ) |
You wanted to play another animation instead of that one animation. So, let's use math.random
. Add a variable before attack:Play()
1 | local RANDOM_ANIM = math.random( 1 , 2 ) |
2 |
3 | if RANDOM_ANIM = = 1 then |
4 | attack 1 :Play() |
5 | elseif RANDOM_ANIM = = 2 then |
6 | attack 2 :Play() |
7 | end |
Your script should look like this:
01 | local CanAttack = true |
02 |
03 | script.Parent.Activated:connect( function () |
04 | local attack 1 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack 1 ) |
05 | local attack 2 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack 2 ) |
06 | if CanAttack = = true then |
07 | local RANDOM_ANIM = math.random( 1 , 2 ) |
08 | if RANDOM_ANIM = = 1 then |
09 | attack 1 :Play() |
10 | elseif RANDOM_ANIM = = 2 then |
11 | attack 2 :Play() |
12 | end |
13 | CanAttack = false |
14 | wait( 1 ) |
15 | attack 1 :Stop() |
16 | attack 2 :Stop() |
17 | CanAttack = true |
18 | script.Parent.CanDamage.Value = true |
19 | end |
20 | end ) |
Remember to rename your 1st animation attack1
and name your 2nd animation attack2
.
If you want to add more animations, then change the math.random
's number range, add a third RANDOM_ANIM, and add make the animation stop.