function playAnimation(U,j,H)if U~=currentAnim then if oldAnimTrack~=nil then oldAnimTrack:Stop()oldAnimTrack:Destroy()end local A=math.random(1,animTable[U].totalWeight)local Q=A local u=1 while A>animTable[U][u].weight do A=A-animTable[U][u].weight u=u+1 end local Y=animTable[U][u].anim oldAnimTrack=currentAnimTrack currentAnimTrack=H:LoadAnimation(Y)currentAnimTrack:Play(j)currentAnim=U if currentAnimKeyframeHandler~=nil then currentAnimKeyframeHandler:disconnect()end currentAnimKeyframeHandler=currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)end end
-- Preload animations
function playAnimation(animName, transitionTime, humanoid)
	if animName ~= currentAnim then
		if oldAnimTrack ~= nil then
			oldAnimTrack:Stop()
			oldAnimTrack:Destroy()
		end

		local roll = math.random(1, animTable[animName].totalWeight)
		local origRoll = roll
		local idx = 1
		while roll > animTable[animName][idx].weight do
			roll = roll - animTable[animName][idx].weight
			idx = idx + 1
		end
		--		print(animName .. " " .. idx .. " [" .. origRoll .. "]")
		local anim = animTable[animName][idx].anim

		-- load it to the humanoid; get AnimationTrack
		oldAnimTrack = currentAnimTrack
		currentAnimTrack = humanoid:LoadAnimation(anim)

		-- play the animation
		currentAnimTrack:Play(transitionTime)
		currentAnim = animName

		-- set up keyframe name triggers
		if currentAnimKeyframeHandler ~= nil then
			currentAnimKeyframeHandler:disconnect()
		end
		currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
	end
end
