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

I want to add more the 1 animation to sword how?

Asked by 7 years ago
Edited 7 years ago

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

01script.Parent.blade.Touched:connect(function(p)
02 
03if script.Parent.CanDamage.Value == true then
04 
05script.Parent.CanDamage.Value = false
06 
07p.Parent.Humanoid:TakeDamage(20)
08 
09end
10 
11end)

SECOND SCRIPT

01local CanAttack = true
02 
03 
04 
05 
06 
07script.Parent.Activated:connect(function()
08 
09local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
10 
11 
12 
13if CanAttack == true then
14 
15attack:Play()
View all 29 lines...

I use this 2 scripts plz help me i rlly want to add more then 1 animation to my sword

1 answer

Log in to vote
1
Answered by
Jxemes 75
7 years ago

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

1local 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).
3if number == 1 then
4--If the number has chosen 1 then
5    print("One has been chosen")
6elseif number == 2 then
7--If the number isn't any number other than 2, then
8    print("Two has been chosen")
9end

Without the comments:

1local number = math.random(1, 2)
2if number == 1 then
3    print("One has been chosen")
4elseif number == 2 then
5    print("Two has been chosen")
6end

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.

01local CanAttack = true
02 
03 
04 
05 
06 
07script.Parent.Activated:connect(function()
08 
09local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
10 
11 
12 
13if CanAttack == true then
14 
15attack:Play()
View all 29 lines...

Before adding the math.random part, you need to make a second variable to the second aniimation.

1local attack1 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack1)
2local attack2 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack2)

You wanted to play another animation instead of that one animation. So, let's use math.random. Add a variable before attack:Play()

1local RANDOM_ANIM = math.random(1, 2)
2 
3if RANDOM_ANIM == 1 then
4    attack1:Play()
5elseif RANDOM_ANIM == 2 then
6    attack2:Play()
7end

Your script should look like this:

01local CanAttack = true
02 
03script.Parent.Activated:connect(function()
04    local attack1 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack1)
05    local attack2 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack2)
06    if CanAttack == true then
07        local RANDOM_ANIM = math.random(1, 2)
08        if RANDOM_ANIM == 1 then
09        attack1:Play()
10        elseif RANDOM_ANIM == 2 then
11        attack2:Play()
12    end
13    CanAttack = false
14    wait(1)
15    attack1:Stop()
16    attack2:Stop()
17    CanAttack = true
18    script.Parent.CanDamage.Value = true
19    end
20end)

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.

0
OMG TYYYY PeacefulTortu 1 — 7y
Ad

Answer this question