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

Sword only playing 1 animation instead of 2?

Hi, so I have a sword with a folder named "Animations" with 3 animations inside: "Attack1" "Attack2" "Idle"

I also have a local script inside the tool named "Client"

The part that needs changing inside Client Code:

local db = true
local Animation = script.Parent.Parent.Humanoid:LoadAnimation(Attack_Animations[Anim_Name..Attack_Num])


Tool.Activated:Connect(function()
	OneHit.Value = true
				if db == true then
            db = false
			Animation:Play()
			Audio:Play()
		wait(0.7)
		if Attack_Num == 1 then
			Attack_Num = Attack_Num + 1
		else if Attack_Num == 2 then
				Attack_Num = 1
			end
		end
			db = true
				end
end)

The thing is that it would only do Attack1 animation and not Attack2. I have also tried putting line 1 inside the tool.Activated function. It works but after a bit it comes up with the error AnimationTrack limit of 256 tracks for one Animator exceeded, new animations will not be played. Please help.

1 comment

0

line 2 is local Animation = script.Parent.Parent.Humanoid:LoadAnimation(Attack_Animations[Anim_Name..Attack_Num])

1 answer

✓ Accepted answer
--//Attacking Animations\\--
local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent
local CanAttack = true
local Audio = script.Parent:WaitForChild("Handle"):WaitForChild("Swing")
local Attack_Animations = Tool:WaitForChild("Animations")
local blade = Tool:WaitForChild("ScytheBlade")
local RE = Tool.RemoteEvent
local OneHitEvent = Tool.OneHitEvent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Animation1 = Player.Character.Humanoid:LoadAnimation(Attack_Animations.Attack1)
local Animation2 = Player.Character.Humanoid:LoadAnimation(Attack_Animations.Attack2)
local Idle = Player.Character.Humanoid:LoadAnimation(script.Parent.Animations.Idle)
local AttackNumber = 0

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

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

blade.Touched:Connect(function(hit)
    if not CanAttack then
		OneHitEvent:FireServer()
		RE:FireServer()
    end
end)

Tool.Activated:Connect(function()
	if CanAttack then
		CanAttack = false
		if AttackNumber % 2 == 1 then
			Animation1:Play()
		else
			Animation2:Play()
		end
		Audio:Play()
		wait(0.7)
		AttackNumber += 1
		CanAttack = true
	end
end)

This script uses a modulo "switching" function to ensure each one gets played an even amount of times

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