How would i make animations play in a certain order on every swing of a sword

Heres what im using so far but i need to know what to do after

local AnimationsFolder = Tool:WaitForChild("Animations")

local anims = {
   AnimationsFolder:WaitForChild("Swing1"),
   AnimationsFolder:WaitForChild("Swing2"),
   AnimationsFolder:WaitForChild("Swing3"),
} 

what would i do after this

Just add a variable to keep track of the current animation. Here is a function that goes over the logic. The actual activation via tool :Activate is not included.

local AnimationsFolder = Tool:WaitForChild("Animations")

local anims = {
   AnimationsFolder:WaitForChild("Swing1"),
   AnimationsFolder:WaitForChild("Swing2"),
   AnimationsFolder:WaitForChild("Swing3"),
} 
local currentAnimationNumber = 1

local function playSwingSwordAnimation()
	local maxAnimationNumber = #anims
	local currentAnimationTrack = anims[currentAnimationNumber] -- play
--do whatever you want with the currentAnimationTrack,
currentAnimationTrack:Play()
	--increase animation number, to go to next animation
	currentAnimationNumber += 1
	--check if it exceeds max animations provided
	if currentAnimationNumber > maxAnimationNumber then
		--reset animation number if so
		currentAnimationNumber = 1
	end
end

--whenever you activate and swing you sword, use this function to play the current animation and cycle to the next one
playSwingSwordAnimation()
1 Like

error Im getting this error (its happening on currentAnimationTrack:Play()

Oh for this you need to substitute the values in the anim table with the loaded animation track that is returned from this function Animator | Roblox Creator Documentation, make sure to use a for loop to automate this process. Forgot to mention this sorry.

1 Like

Can i have an example? It would be a lot easier for me because i’ve read that before i came to the devforum to ask.

This is spoon feeding, but yeah here you go, don’t rely on it too often and google search your errors next time.

local player = game.Players.LocalPlayer--make sure its a local script
local character = player.Character or player.CharacterAdded:Wait()
local animator : Animator = character:WaitForChild"Humanoid":WaitForChild"Animator"
local anims = {
	AnimationsFolder:WaitForChild("Swing1"),
	AnimationsFolder:WaitForChild("Swing2"),
	AnimationsFolder:WaitForChild("Swing3"),
 } 
for index,animation in ipairs(anims) do--ipairs because its an array
	anims[index] = animator:LoadAnimation(animation) -- replace animation with animation track
end
2 Likes

It worked. Thank you! <3 You were so helpful.

1 Like