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

How do i make a Sword that plays 2 Animations?

So i have this script that is sposed to play 2 different animations. It plays the first animation just fine but it wont play the second and the tool stops working after the first animation. I've spent quite a long time trying to figure this out but i don't know whats wrong.

local Tool = script.Parent
local Cooldown = script.Cooldown.Value
local animation1 = script.Swing
local animation2 = script.NewSwing
local animvalue = 1

Tool.Activated:Connect(function()
	if animvalue == 1 then
	animvalue = 2
	local Humanoid = Tool.Parent:FindFirstChildWhichIsA("Humanoid")
	if Humanoid and Cooldown == false then
		Cooldown = true
		local playanimation = Humanoid:LoadAnimation(animation1)
		playanimation:Play()
		Tool.SwordBlade.Damage.Disabled = false
		wait(0.3)
		playanimation:Stop()
		Tool.SwordBlade.Damage.Disabled = true
			wait(0.5)
		Cooldown = false
		else
		animvalue = 1
	local Humanoid = Tool.Parent:FindFirstChildWhichIsA("Humanoid")
	if Humanoid and Cooldown == false then
		Cooldown = true
		local playanimation = Humanoid:LoadAnimation(animation2)
		playanimation:Play()
		Tool.SwordBlade.Damage.Disabled = false
		wait(0.3)
		playanimation:Stop()
		Tool.SwordBlade.Damage.Disabled = true
			wait(0.5)
		Cooldown = false
			end
		end
	end
end)

1 comment

0

i think i might have figured it out

1 answer

Ok So i Answered this Myself

My Else Statement on line 21 was Corresponding with Line 11's If Statement when i wanted it to Correspond with Line 8's If Statement so i reworked the code and came up with this


local Tool = script.Parent
local Cooldown = script.Cooldown.Value
local animation1 = script.Swing
local animation2 = script.NewSwing
local animvalue = 1

Tool.Activated:Connect(function()
	local Humanoid = Tool.Parent:FindFirstChildWhichIsA("Humanoid")
	if Humanoid and Cooldown == false then
		if animvalue == 1 then
			animvalue = 2
		Cooldown = true
		local playanimation = Humanoid:LoadAnimation(animation1)
		playanimation:Play()
		Tool.SwordBlade.Damage.Disabled = false
		wait(0.3)
		playanimation:Stop()
		Tool.SwordBlade.Damage.Disabled = true
			wait(0.5)
			Cooldown = false
		else if animvalue == 2 then
			animvalue = 1
	local Humanoid = Tool.Parent:FindFirstChildWhichIsA("Humanoid")
	if Humanoid and Cooldown == false then
		Cooldown = true
		local playanimation = Humanoid:LoadAnimation(animation2)
		playanimation:Play()
		Tool.SwordBlade.Damage.Disabled = false
		wait(0.3)
		playanimation:Stop()
		Tool.SwordBlade.Damage.Disabled = true
			wait(0.5)
		Cooldown = false
				end
			end
		end
	end
end)

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