local y={wave=false;point=false;dance=true,dance2=true;dance3=true,laugh=false;cheer=false}math.randomseed(tick())function findExistingAnimationInSet(y,m)if y==nil or m==nil then return 0 end for R=1,y.count,1 do if y[R].anim.AnimationId==m.AnimationId then return R end end return 0 end function configureAnimationSet(y,m)if animTable[y]~=nil then for y,m in pairs(animTable[y].connections)do m:disconnect()end end animTable[y]={}animTable[y].count=0 animTable[y].totalWeight=0 animTable[y].connections={}local R=script:FindFirstChild(y)if R~=nil then table.insert(animTable[y].connections,R.ChildAdded:connect(function(R)configureAnimationSet(y,m)end))table.insert(animTable[y].connections,R.ChildRemoved:connect(function(R)configureAnimationSet(y,m)end))local W=0 for R,p in pairs(R:GetChildren())do if p:IsA("\065\110\105\109\097\116\105\111\110")then local R=1 local g=p:FindFirstChild("\087\101\105\103\104\116")if g~=nil then R=g.Value end animTable[y].count=animTable[y].count+1 W=animTable[y].count animTable[y][W]={}animTable[y][W].anim=p animTable[y][W].weight=R animTable[y].totalWeight=animTable[y].totalWeight+animTable[y][W].weight table.insert(animTable[y].connections,p.Changed:connect(function(R)configureAnimationSet(y,m)end))table.insert(animTable[y].connections,p.ChildAdded:connect(function(R)configureAnimationSet(y,m)end))table.insert(animTable[y].connections,p.ChildRemoved:connect(function(R)configureAnimationSet(y,m)end))local Q=p:GetAttribute("\076\105\110\101\097\114\086\101\108\111\099\105\116\121")if Q then strafingLocomotionMap[y]={lv=Q,speed=Q.Magnitude}end if y=="\114\117\110"or y=="\119\097\108\107"then if Q then fallbackLocomotionMap[y]=strafingLocomotionMap[y]else local m=y=="\114\117\110"and RUN_SPEED or WALK_SPEED fallbackLocomotionMap[y]={lv=Vector2.new(.0,m);speed=m}locomotionMap=fallbackLocomotionMap warn("\083\116\114\097\102\101 \098\108\101\110\100\105\110\103 \100\105\115\097\098\108\101\100\046 \078\111 \108\105\110\101\097\114 \118\101\108\111\099\105\116\121 \105\110\102\111\114\109\097\116\105\111\110 \102\111\114 \"\119\097\108\107\" \097\110\100 \"\114\117\110\"\046")end end end end end if animTable[y].count<=0 then for m,R in pairs(m)do animTable[y][m]={}animTable[y][m].anim=Instance.new("\065\110\105\109\097\116\105\111\110")animTable[y][m].anim.Name=y animTable[y][m].anim.AnimationId=R.id animTable[y][m].weight=R.weight animTable[y].count=animTable[y].count+1 animTable[y].totalWeight=animTable[y].totalWeight+R.weight end end for y,m in pairs(animTable)do for y=1,m.count,1 do if PreloadedAnims[m[y].anim.AnimationId]==nil then Humanoid:LoadAnimation(m[y].anim)PreloadedAnims[m[y].anim.AnimationId]=true end 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, dance = true, dance2 = true, dance3 = true, laugh = false, cheer = false }

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

	-- check for config values
	local config = script:FindFirstChild(name)
	if 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)
				)
				local lv = childPart:GetAttribute("LinearVelocity")
				if lv then
					strafingLocomotionMap[name] = { lv = lv, speed = lv.Magnitude }
				end
				if name == "run" or name == "walk" then
					if lv then
						fallbackLocomotionMap[name] = strafingLocomotionMap[name]
					else
						local speed = name == "run" and RUN_SPEED or WALK_SPEED
						fallbackLocomotionMap[name] = { lv = Vector2.new(0.0, speed), speed = speed }
						locomotionMap = fallbackLocomotionMap
						-- If you don't have a linear velocity with your run or walk, you can't blend/strafe
						warn(
							"Strafe blending disabled. No linear velocity information for "
								.. '"'
								.. "walk"
								.. '"'
								.. " and "
								.. '"'
								.. "run"
								.. '"'
								.. "."
						)
					end
				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
	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
