function playAnimation(d,M,b)if d~=currentAnim then if oldAnimTrack~=nil then oldAnimTrack:Stop()oldAnimTrack:Destroy()end local f=math.random(1,animTable[d].totalWeight)local t=f local v=1 while f>animTable[d][v].weight do f=f-animTable[d][v].weight v=v+1 end local w=animTable[d][v].anim oldAnimTrack=currentAnimTrack currentAnimTrack=b:LoadAnimation(w)currentAnimTrack:Play(M)currentAnim=d if currentAnimKeyframeHandler~=nil then currentAnimKeyframeHandler:disconnect()end currentAnimKeyframeHandler=currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)end end

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
	