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
local number = math.random(1, 2)
if number == 1 then
print("One has been chosen")
elseif number == 2 then
print("Two has been chosen")
end
Without the comments:
local number = math.random(1, 2)
if number == 1 then
print("One has been chosen")
elseif number == 2 then
print("Two has been chosen")
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.
local CanAttack = true
script.Parent.Activated:connect(function()
local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
if CanAttack == true then
attack:Play()
CanAttack = false
wait(1)
attack:Stop()
CanAttack = true
script.Parent.CanDamage.Value = true
end
end)
Before adding the math.random part, you need to make a second variable to the second aniimation.
local attack1 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack1)
local 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()
local RANDOM_ANIM = math.random(1, 2)
if RANDOM_ANIM == 1 then
attack1:Play()
elseif RANDOM_ANIM == 2 then
attack2:Play()
end
Your script should look like this:
local CanAttack = true
script.Parent.Activated:connect(function()
local attack1 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack1)
local attack2 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack2)
if CanAttack == true then
local RANDOM_ANIM = math.random(1, 2)
if RANDOM_ANIM == 1 then
attack1:Play()
elseif RANDOM_ANIM == 2 then
attack2:Play()
end
CanAttack = false
wait(1)
attack1:Stop()
attack2:Stop()
CanAttack = true
script.Parent.CanDamage.Value = true
end
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.
1 comment
OMG TYYYY