local w={wave=false,point=false;dance=true;dance2=true,dance3=true,laugh=false;cheer=false}local i=false local Y={}local W,o=pcall(function()i=(UserSettings()):IsUserFeatureEnabled("\085\115\101\114\080\114\101\108\111\097\100\065\110\105\109\097\116\105\111\110\115")end)if not W then i=false end math.randomseed(tick())function findExistingAnimationInSet(w,i)if w==nil or i==nil then return 0 end for Y=1,w.count,1 do if w[Y].anim.AnimationId==i.AnimationId then return Y end end return 0 end function configureAnimationSet(w,W)if animTable[w]~=nil then for w,i in pairs(animTable[w].connections)do i:disconnect()end end animTable[w]={}animTable[w].count=0 animTable[w].totalWeight=0 animTable[w].connections={}local o=true local v,k=pcall(function()o=(game:GetService("\083\116\097\114\116\101\114\080\108\097\121\101\114")).AllowCustomAnimations end)if not v then o=true end local C=script:FindFirstChild(w)if o and C~=nil then table.insert(animTable[w].connections,C.ChildAdded:connect(function(i)configureAnimationSet(w,W)end))table.insert(animTable[w].connections,C.ChildRemoved:connect(function(i)configureAnimationSet(w,W)end))local i=0 for Y,o in pairs(C:GetChildren())do if o:IsA("\065\110\105\109\097\116\105\111\110")then local Y=1 local v=o:FindFirstChild("\087\101\105\103\104\116")if v~=nil then Y=v.Value end animTable[w].count=animTable[w].count+1 i=animTable[w].count animTable[w][i]={}animTable[w][i].anim=o animTable[w][i].weight=Y animTable[w].totalWeight=animTable[w].totalWeight+animTable[w][i].weight table.insert(animTable[w].connections,o.Changed:connect(function(i)configureAnimationSet(w,W)end))table.insert(animTable[w].connections,o.ChildAdded:connect(function(i)configureAnimationSet(w,W)end))table.insert(animTable[w].connections,o.ChildRemoved:connect(function(i)configureAnimationSet(w,W)end))end end end if animTable[w].count<=0 then for i,Y in pairs(W)do animTable[w][i]={}animTable[w][i].anim=Instance.new("\065\110\105\109\097\116\105\111\110")animTable[w][i].anim.Name=w animTable[w][i].anim.AnimationId=Y.id animTable[w][i].weight=Y.weight animTable[w].count=animTable[w].count+1 animTable[w].totalWeight=animTable[w].totalWeight+Y.weight end end if i then for w,i in pairs(animTable)do for w=1,i.count,1 do if Y[i[w].anim.AnimationId]==nil then Humanoid:LoadAnimation(i[w].anim)Y[i[w].anim.AnimationId]=true end end end end end

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

local PreloadAnimsUserFlag = false
local PreloadedAnims = {}
local successPreloadAnim, msgPreloadAnim = pcall(function()
	PreloadAnimsUserFlag = UserSettings():IsUserFeatureEnabled("UserPreloadAnimations")
end)
if not successPreloadAnim then
	PreloadAnimsUserFlag = false
end

math.randomseed(tick())

function findExistingAnimationInSet(set, anim)
	if set == nil or anim == nil then
		return 0
	end
	
	for idx = 1, set.count, 1 do 
		if set[idx].anim.AnimationId == anim.AnimationId then
			return idx
		end
	end
	
	return 0
end

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 = {}

	local allowCustomAnimations = true

	local success, msg = pcall(function() allowCustomAnimations = game:GetService("StarterPlayer").AllowCustomAnimations end)
	if not success then
		allowCustomAnimations = true
	end

	-- check for config values
	local config = script:FindFirstChild(name)
	if (allowCustomAnimations and config ~= nil) then
		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 = 0
		for _, childPart in pairs(config:GetChildren()) do
			if (childPart:IsA("Animation")) then
				local newWeight = 1
				local weightObject = childPart:FindFirstChild("Weight")
				if (weightObject ~= nil) then
					newWeight = weightObject.Value
				end
				animTable[name].count = animTable[name].count + 1
				idx = animTable[name].count
				animTable[name][idx] = {}
				animTable[name][idx].anim = childPart
				animTable[name][idx].weight = newWeight
				animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
				table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
				table.insert(animTable[name].connections, childPart.ChildAdded:connect(function(property) configureAnimationSet(name, fileList) end))
				table.insert(animTable[name].connections, childPart.ChildRemoved:connect(function(property) configureAnimationSet(name, fileList) end))
			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
		end
	end
	
	-- preload anims
	if PreloadAnimsUserFlag then
		for i, animType in pairs(animTable) do
			for idx = 1, animType.count, 1 do
				if PreloadedAnims[animType[idx].anim.AnimationId] == nil then
					Humanoid:LoadAnimation(animType[idx].anim)
					PreloadedAnims[animType[idx].anim.AnimationId] = true
				end				
			end
		end
	end
end
