local p={wave=false;point=false;dance1=true;dance2=true;dance3=true,laugh=false;cheer=false}function configureAnimationSet(p,R)if animTable[p]~=nil then for p,R in pairs(animTable[p].connections)do R:disconnect()end end animTable[p]={}animTable[p].count=0 animTable[p].totalWeight=0 animTable[p].connections={}local A=script:FindFirstChild(p)if A~=nil then table.insert(animTable[p].connections,A.ChildAdded:connect(function(A)configureAnimationSet(p,R)end))table.insert(animTable[p].connections,A.ChildRemoved:connect(function(A)configureAnimationSet(p,R)end))local c=1 for A,e in pairs(A:GetChildren())do if e:IsA("\065\110\105\109\097\116\105\111\110")then table.insert(animTable[p].connections,e.Changed:connect(function(A)configureAnimationSet(p,R)end))animTable[p][c]={}animTable[p][c].anim=e local A=e:FindFirstChild("\087\101\105\103\104\116")if A==nil then animTable[p][c].weight=1 else animTable[p][c].weight=A.Value end animTable[p].count=animTable[p].count+1 animTable[p].totalWeight=animTable[p].totalWeight+animTable[p][c].weight c=c+1 end end end if animTable[p].count<=0 then for R,A in pairs(R)do animTable[p][R]={}animTable[p][R].anim=Instance.new("\065\110\105\109\097\116\105\111\110")animTable[p][R].anim.Name=p animTable[p][R].anim.AnimationId=A.id animTable[p][R].weight=A.weight animTable[p].count=animTable[p].count+1 animTable[p].totalWeight=animTable[p].totalWeight+A.weight end end end

local emoteNames = { wave = false, point = false, dance1 = true, dance2 = true, dance3 = true, laugh = false, cheer = false}

function configureAnimationSet(name, fileList)
    if (animTable[name] ~= nil) then
        for _, connection in pairs(animTable[name].connections) do
            connection:disconnect()
        end
    end
    animTable[name] = {}
    animTable[name].count = 0
    animTable[name].totalWeight = 0
    animTable[name].connections = {}

    -- check for config values
    local config = script:FindFirstChild(name)
    if (config ~= nil) then
        --print("Loading anims " .. name)
        table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
        table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
        local idx = 1
        for _, childPart in pairs(config:GetChildren()) do
            if (childPart:IsA("Animation")) then
                table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
                animTable[name][idx] = {}
                animTable[name][idx].anim = childPart
                local weightObject = childPart:FindFirstChild("Weight")
                if (weightObject == nil) then
                    animTable[name][idx].weight = 1
                else
                    animTable[name][idx].weight = weightObject.Value
                end
                animTable[name].count = animTable[name].count + 1
                animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
                --print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
                idx = idx + 1
            end
        end
    end

    -- fallback to defaults
    if (animTable[name].count <= 0) then
        for idx, anim in pairs(fileList) do
            animTable[name][idx] = {}
            animTable[name][idx].anim = Instance.new("Animation")
            animTable[name][idx].anim.Name = name
            animTable[name][idx].anim.AnimationId = anim.id
            animTable[name][idx].weight = anim.weight
            animTable[name].count = animTable[name].count + 1
            animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
            --print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
        end
    end
end
