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