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()
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.
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