function playAnimation(w,r,e)local b=math.random(1,animTable[w].totalWeight)local V=b local O=1 while b>animTable[w][O].weight do b=b-animTable[w][O].weight O=O+1 end local Z=animTable[w][O].anim if Z~=currentAnimInstance then if currentAnimTrack~=nil then currentAnimTrack:Stop(r)currentAnimTrack:Destroy()end currentAnimSpeed=1.0 currentAnimTrack=e:LoadAnimation(Z)currentAnimTrack.Priority=Enum.AnimationPriority.Core currentAnimTrack:Play(r)currentAnim=w currentAnimInstance=Z if currentAnimKeyframeHandler~=nil then currentAnimKeyframeHandler:disconnect()end currentAnimKeyframeHandler=currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)end end

function playAnimation(animName, transitionTime, humanoid) 

	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

	-- switch animation		
	if (anim ~= currentAnimInstance) then

		if (currentAnimTrack ~= nil) then
			currentAnimTrack:Stop(transitionTime)
			currentAnimTrack:Destroy()
		end

		currentAnimSpeed = 1.0

		-- load it to the humanoid; get AnimationTrack
		currentAnimTrack = humanoid:LoadAnimation(anim)
		currentAnimTrack.Priority = Enum.AnimationPriority.Core

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

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

	end

end
