local c=""local k=nil local A=nil local o=nil function toolKeyFrameReachedFunc(k)if k=="\069\110\100"then playToolAnimation(c,.0,Humanoid)end end function playToolAnimation(b,N,w,P)local S=math.random(1,animTable[b].totalWeight)local Q=S local G=1 while S>animTable[b][G].weight do S=S-animTable[b][G].weight G=G+1 end local D=animTable[b][G].anim if A~=D then if k~=nil then k:Stop()k:Destroy()N=0 end k=w:LoadAnimation(D)if P then k.Priority=P end k:Play(N)c=b A=D o=k.KeyframeReached:connect(toolKeyFrameReachedFunc)end end function stopToolAnimations()local b=c if o~=nil then o:disconnect()end c=""A=nil if k~=nil then k:Stop()k:Destroy()k=nil end return b 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, priority)	 

	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)
		if priority then
			toolAnimTrack.Priority = priority
		end

		-- 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
