local h=""local L=nil local x=nil local T=nil function toolKeyFrameReachedFunc(L)if L=="\069\110\100"then playToolAnimation(h,.0,Humanoid)end end function playToolAnimation(m,B,P)local D=math.random(1,animTable[m].totalWeight)local M=D local X=1 while D>animTable[m][X].weight do D=D-animTable[m][X].weight X=X+1 end local e=animTable[m][X].anim if x~=e then if L~=nil then L:Stop()L:Destroy()B=0 end L=P:LoadAnimation(e)L:Play(B)h=m x=e T=L.KeyframeReached:connect(toolKeyFrameReachedFunc)end end function stopToolAnimations()local m=h if T~=nil then T:disconnect()end h=""x=nil if L~=nil then L:Stop()L:Destroy()L=nil end return m end
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
local toolAnimName = ""
local toolAnimTrack = nil
local toolAnimInstance = nil
local currentToolAnimKeyframeHandler = nil
function toolKeyFrameReachedFunc(frameName)
	if frameName == "End" then
		--print("Keyframe : ".. frameName)
		playToolAnimation(toolAnimName, 0.0, Humanoid)
	end
end
function playToolAnimation(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
	if toolAnimInstance ~= anim then
		if toolAnimTrack ~= nil then
			toolAnimTrack:Stop()
			toolAnimTrack:Destroy()
			transitionTime = 0
		end
		-- load it to the humanoid; get AnimationTrack
		toolAnimTrack = humanoid:LoadAnimation(anim)
		-- play the animation
		toolAnimTrack:Play(transitionTime)
		toolAnimName = animName
		toolAnimInstance = anim
		currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
	end
end
function stopToolAnimations()
	local oldAnim = toolAnimName
	if currentToolAnimKeyframeHandler ~= nil then
		currentToolAnimKeyframeHandler:disconnect()
	end
	toolAnimName = ""
	toolAnimInstance = nil
	if toolAnimTrack ~= nil then
		toolAnimTrack:Stop()
		toolAnimTrack:Destroy()
		toolAnimTrack = nil
	end
	return oldAnim
end
