local n=""local M=nil local h=nil local P=nil function toolKeyFrameReachedFunc(n)if n=="\069\110\100"then local n=stopToolAnimations()playToolAnimation(n,.0,Humanoid)end end function playToolAnimation(L,V,f)if L~=n then if h~=nil then h:Stop()h:Destroy()V=0 end local K=math.random(1,animTable[L].totalWeight)local y=K local t=1 while K>animTable[L][t].weight do K=K-animTable[L][t].weight t=t+1 end local O=animTable[L][t].anim M=h h=f:LoadAnimation(O)h:Play(V)n=L P=h.KeyframeReached:connect(toolKeyFrameReachedFunc)end end function stopToolAnimations()local M=n if P~=nil then P:disconnect()end n=""if h~=nil then h:Stop()h:Destroy()h=nil end return M end

	
local toolAnimName = ""
local toolOldAnimTrack = nil
local toolAnimTrack = nil
local currentToolAnimKeyframeHandler = nil
	
function toolKeyFrameReachedFunc(frameName)
	if (frameName == "End") then
		--		print("Keyframe : ".. frameName)
		local repeatAnim = stopToolAnimations()
		playToolAnimation(repeatAnim, 0.0, Humanoid)
	end
end
	
	
function playToolAnimation(animName, transitionTime, humanoid)
	if (animName ~= toolAnimName) then		 
			
		if (toolAnimTrack ~= nil) then
			toolAnimTrack:Stop()
			toolAnimTrack:Destroy()
			transitionTime = 0
		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
		toolOldAnimTrack = toolAnimTrack
		toolAnimTrack = humanoid:LoadAnimation(anim)
		 
		-- play the animation
		toolAnimTrack:Play(transitionTime)
		toolAnimName = animName
			
		currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
	end
end
	
function stopToolAnimations()
	local oldAnim = toolAnimName
		
	if (currentToolAnimKeyframeHandler ~= nil) then
		currentToolAnimKeyframeHandler:disconnect()
	end
		
	toolAnimName = ""
	if (toolAnimTrack ~= nil) then
		toolAnimTrack:Stop()
		toolAnimTrack:Destroy()
		toolAnimTrack = nil
	end
		
		
	return oldAnim
end
	