How can i make a sword with 2 attack animations

Slash 2 animation and equip animation is not playing but slash 1 animation is perfectly working how can i fix that?

local WeaponTool = script.Parent.Parent.Parent
local char = game.Players.LocalPlayer.CharacterAdded:Wait()
local randomSlash = 1
WeaponTool.Equipped:Connect(function()
	game.ReplicatedStorage.ConnectM6D:FireServer(WeaponTool.PathmakerModel.BodyAttach)

	char.Torso.ToolGrip.Part0 = char.Torso
	char.Torso.ToolGrip.Part1 = WeaponTool.PathmakerModel.BodyAttach


	char.Humanoid:LoadAnimation(script.Equip):Play()
	wait(2)
	char.Humanoid:LoadAnimation(script.idle):Play()

end)

WeaponTool.Activated:Connect(function()
	
	if WeaponTool.Activated then	
		if randomSlash  == 1 then
			char.Humanoid:LoadAnimation(script.idle):Stop()
			char.Humanoid:LoadAnimation(script.Attack1):Play()
			char.Humanoid:LoadAnimation(script.idle):Play()
			randomSlash +=1
	end
		
		if randomSlash == 2 then
			char.Humanoid:LoadAnimation(script.idle):Stop()
			char.Humanoid:LoadAnimation(script.Attack2):Play()
			char.Humanoid:LoadAnimation(script.idle):Play()
			randomSlash = randomSlash - 1
	end
	

end

WeaponTool.Unequipped:Connect(function()
		game.ReplicatedStorage.DisconnectM6D:FireServer()

   end)
end)

First of all, I do advise loading the animations before using them to optimize.

As in variables. Iā€™ll look forward into the actual issue.

edit: And since this is a clientscript, I suggest using :WaitForChild("") as well.

1 Like

You need to make use of elseif rather than two if statements.
Also, donā€™t worry about stopping the Idle animation before playing an Attack animation. It should automatically work. If not, you can set animation-priorities in the animation.


local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")

local IdleAnim = humanoid:LoadAnimation(script:WaitForChild("idle"))
local Attack1Anim = humanoid:LoadAnimation(script:WaitForChild("Attack1"))
local Attack2Anim = humanoid:LoadAnimation(script:WaitForChild("Attack2"))


WeaponTool.Activated:Connect(function()
	if randomSlash == 1 then
		char.Humanoid:LoadAnimation(script.Attack1):Play()
		randomSlash +=1 --i suggest using math.Random()
	elseif randomSlash == 2 then
		char.Humanoid:LoadAnimation(script.Attack2):Play()
		randomSlash = randomSlash - 1 --i suggest using math.Random()
	end
end)

and if youā€™re planning on only using two attack anims, you can just make it say ā€˜elseā€™ rather than ā€˜elseif randomSlash == 2ā€™ so it doesnā€™t have to check that everyime.

Iā€™m not familiar with the way you make the random-number so if this also doesnā€™t work I suggest using math.Random()

Thank you so much!It worked bro. :upside_down_face:

but how to make a equip animation after tool equipped

sorry for not replying,

first obviously a function to when the player equips, then play the animation inside of it

Tool.Equipped:Connect(function()
IdleAnim:Play()
end)

and then one that stops the animation

Tool.Unequipped:Connect(function()
IdleAnim:Stop()
end)

also, I advise loading the animations in the tool.Equipped function because sometimes it can cause an error. But thatā€™s up to you since you might not have those errors.

whenever i try to load animations with variables before a function i get the ā€œCannot load the AnimationClipProvider Serviceā€ error.