Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

script.Parent.blade.Touched:connect(function(p)

if script.Parent.CanDamage.Value == true then

script.Parent.CanDamage.Value = false

p.Parent.Humanoid:TakeDamage(20)

end

end)

SECOND SCRIPT

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)

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

1 answer

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)
--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).
if number == 1 then
--If the number has chosen 1 then
	print("One has been chosen")
elseif number == 2 then
--If the number isn't any number other than 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

0

OMG TYYYY

This discussion is preserved as it was. New answers, comments, and votes are closed.