Tool animations wont play

I have a tool with a folder called ‘Animations’. I’m trying to load the animations from the folder but for some reason the animations wont play. I click the mouse to attack the enemy but nothing happens.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local tool = nil

local soundsFolder = script:WaitForChild("Sounds", 10)

if not soundsFolder then
    warn("Sounds folder not found in ToolHandlerScript")
end

local damageEnemyEvent = ReplicatedStorage:WaitForChild("DamageEnemy")

-- Function to load animations from the folder inside the tool
local function loadAnimations(humanoid, tool)
    local animationsFolder = tool:WaitForChild("Animations", 10)
    local animationTracks = {}
    if animationsFolder then
        for _, anim in ipairs(animationsFolder:GetChildren()) do
            if anim:IsA("Animation") then
                local track = humanoid:LoadAnimation(anim)
                table.insert(animationTracks, track)
                print("Loaded animation: " .. anim.Name)
            end
        end
    else
        warn("No Animations folder found in tool")
    end
    return animationTracks
end

-- Function to play sound from the folder
local function playSound(soundName, parent)
    if soundsFolder then
        local soundTemplate = soundsFolder:FindFirstChild(soundName)
        if soundTemplate then
            local sound = soundTemplate:Clone()
            sound.Parent = parent
            sound:Play()
            game.Debris:AddItem(sound, sound.TimeLength)
        else
            warn("No sound named " .. soundName .. " found in Sounds folder")
        end
    else
        warn("No Sounds folder found")
    end
end

-- Function to play hit particles
local function playHitParticles(humanoidRootPart, particleName)
    particleName = particleName or "HitParticles"
    local hitParticlesTemplate = ReplicatedStorage:WaitForChild("ParticleEffects"):FindFirstChild(particleName)
    if hitParticlesTemplate then
        local existingParticles = humanoidRootPart:FindFirstChild(particleName)
        if existingParticles then
            existingParticles:Destroy()
        end

        local hitParticles = hitParticlesTemplate:Clone()
        hitParticles.Name = particleName
        hitParticles.Parent = humanoidRootPart
        print("Emitting " .. particleName)
        hitParticles:Emit(30)
        game.Debris:AddItem(hitParticles, 1)
    else
        warn("No " .. particleName .. " template found in ReplicatedStorage")
    end
end

-- Function to show damage numbers
local function showDamageNumber(enemyHumanoid, damage, isCriticalHit)
    local damageNumberTemplate = ReplicatedStorage:WaitForChild("ParticleEffects"):FindFirstChild("DamageNumber")
    if damageNumberTemplate then
        local damageNumber = damageNumberTemplate:Clone()
        damageNumber.Parent = enemyHumanoid.Parent
        damageNumber.Adornee = enemyHumanoid.Parent:FindFirstChild("HumanoidRootPart")

        damageNumber.Size = UDim2.new(2, 0, 1, 0)
        damageNumber.StudsOffset = Vector3.new(0, 3, 0)
        damageNumber.AlwaysOnTop = true

        local textLabel = damageNumber:FindFirstChild("DamageText")
        if textLabel then
            textLabel.Text = tostring(damage)
            textLabel.TextSize = 36
            textLabel.Font = Enum.Font.SourceSansBold
            textLabel.TextStrokeTransparency = 0.5
            textLabel.TextTransparency = 0
            textLabel.BackgroundTransparency = 1
            textLabel.TextScaled = true
            textLabel.Size = UDim2.new(1, 0, 1, 0)

            if isCriticalHit then
                textLabel.TextColor3 = Color3.new(1, 0, 0)
            else
                textLabel.TextColor3 = Color3.new(1, 1, 1)
            end

            local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
            local goalsPosition = {Position = UDim2.new(0, 0, -2, 0)}
            local goalsTransparency = {TextTransparency = 1, TextStrokeTransparency = 1}

            local tweenPosition = TweenService:Create(textLabel, tweenInfo, goalsPosition)
            local tweenTransparency = TweenService:Create(textLabel, tweenInfo, goalsTransparency)

            print("Playing damage number tween")
            tweenPosition:Play()
            tweenTransparency:Play()

            tweenTransparency.Completed:Connect(function()
                damageNumber:Destroy()
            end)
        else
            warn("No TextLabel named 'DamageText' found in DamageNumber")
        end
    else
        warn("No DamageNumber template found in ReplicatedStorage")
    end
end

-- Function to handle damage
local function handleDamage(enemyHumanoid)
    if tool and tool:FindFirstChild("Stats") then
        local stats = tool:FindFirstChild("Stats")
        local baseDamage = stats:FindFirstChild("BaseDamage") and stats.BaseDamage.Value or 10
        local level = stats:FindFirstChild("Level") and stats.Level.Value or 1
        print("BaseDamage: ", baseDamage)
        print("Level: ", level)

        local damagePerLevel = 0.2
        local totalDamage = baseDamage + (level * damagePerLevel)

        local isCriticalHit = math.random() < 0.2
        if isCriticalHit then
            totalDamage = totalDamage * 2
        end

        print("Applying damage: ", totalDamage)
        enemyHumanoid:TakeDamage(totalDamage)
        print("Damage applied")

        playSound("HitSound", enemyHumanoid.Parent)

        local humanoidRootPart = enemyHumanoid.Parent:FindFirstChild("HumanoidRootPart")
        if humanoidRootPart then
            playHitParticles(humanoidRootPart)
        else
            warn("No HumanoidRootPart found for " .. enemyHumanoid.Parent.Name)
        end

        if isCriticalHit then
            print("Critical hit detected")
            playSound("CriticalHitSound", enemyHumanoid.Parent)
            playHitParticles(humanoidRootPart, "CriticalHitParticles")
        end

        showDamageNumber(enemyHumanoid, totalDamage, isCriticalHit)
    else
        warn("No valid tool or stats found")
    end
end

local function setupTool(tool)
    local humanoid = character:WaitForChild("Humanoid")
    local animationTracks = loadAnimations(humanoid, tool)

    if #animationTracks == 0 then
        warn("No animations loaded")
        return
    end

    local bladeSensor = tool:WaitForChild("BladeSensor", true)
    local isAttacking = false
    local currentAnimationIndex = 1

    tool.Activated:Connect(function()
        if isAttacking then return end
        isAttacking = true

        local swingTrack = animationTracks[currentAnimationIndex]
        if swingTrack and swingTrack.IsPlaying then
            swingTrack:Stop()
        end
        if swingTrack then
            print("Playing animation: " .. swingTrack.Animation.AnimationId)
            swingTrack:Play()
            playSound("SwingSound", tool.Handle)
        end

        swingTrack.Stopped:Connect(function()
            isAttacking = false
            currentAnimationIndex = currentAnimationIndex % #animationTracks + 1
        end)

        swingTrack:GetMarkerReachedSignal("DealDamage"):Connect(function()
            local connection
            connection = game:GetService("RunService").RenderStepped:Connect(function()
                if swingTrack.IsPlaying then
                    local region = Region3.new(
                        bladeSensor.Position - Vector3.new(2.5, 2.5, 2.5),
                        bladeSensor.Position + Vector3.new(2.5, 2.5, 2.5)
                    )
                    local parts = workspace:FindPartsInRegion3WithIgnoreList(region, {character})
                    for _, instance in ipairs(parts) do
                        if instance.Name == "Hitbox" and instance.Parent:FindFirstChild("Humanoid") then
                            handleDamage(instance.Parent.Humanoid)
                        end
                    end
                else
                    connection:Disconnect()
                end
            end)
        end)
    end)
end

-- Listen for tool equipped
player.CharacterAdded:Connect(function(char)
    character = char
    character.ChildAdded:Connect(function(child)
        if child:IsA("Tool") then
            tool = child
            setupTool(tool)
        end
    end)
end)

-- Handle already equipped tool if character is already loaded
if character then
    for _, child in ipairs(character:GetChildren()) do
        if child:IsA("Tool") then
            tool = child
            setupTool(tool)
        end
    end
end)

No errors in the output so im not sure where the error is happening at.