local r={wave=false;point=false;dance1=true;dance2=true,dance3=true,laugh=false;cheer=false}function configureAnimationSet(r,X)if animTable[r]~=nil then for r,X in pairs(animTable[r].connections)do X:disconnect()end end animTable[r]={}animTable[r].count=0 animTable[r].totalWeight=0 animTable[r].connections={}local v=script:FindFirstChild(r)if v~=nil then table.insert(animTable[r].connections,v.ChildAdded:connect(function(v)configureAnimationSet(r,X)end))table.insert(animTable[r].connections,v.ChildRemoved:connect(function(v)configureAnimationSet(r,X)end))local V=1 for v,I in pairs(v:GetChildren())do if I:IsA("\065\110\105\109\097\116\105\111\110")then table.insert(animTable[r].connections,I.Changed:connect(function(v)configureAnimationSet(r,X)end))animTable[r][V]={}animTable[r][V].anim=I local v=I:FindFirstChild("\087\101\105\103\104\116")if v==nil then animTable[r][V].weight=1 else animTable[r][V].weight=v.Value end animTable[r].count=animTable[r].count+1 animTable[r].totalWeight=animTable[r].totalWeight+animTable[r][V].weight V=V+1 end end end if animTable[r].count<=0 then for X,v in pairs(X)do animTable[r][X]={}animTable[r][X].anim=Instance.new("\065\110\105\109\097\116\105\111\110")animTable[r][X].anim.Name=r animTable[r][X].anim.AnimationId=v.id animTable[r][X].weight=v.weight animTable[r].count=animTable[r].count+1 animTable[r].totalWeight=animTable[r].totalWeight+v.weight end end end
-- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
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
