local function T(T,Y)while not T:FindFirstChild(Y)do T.ChildAdded:wait()end return T[Y]end local Y=script.Parent local J={}local I local G local h=T(script,"\083\116\097\114\116")local P=T(script,"\083\116\111\112")function PlayAnimation(T,Y)Y=Y or 1 if J[T]then J[T]:Play(.1,1,Y)else print("\067\097\110\'\116 \102\105\110\100 \097\110\105\109\097\116\105\111\110\058",T)end end function StopAnimation(T)if J[T]then J[T]:Stop()end end function ConnectAnimationToValueChange(J,I)return(T(Y,J)).Changed:connect(function(T)PlayAnimation(I)end)end function LoadAnimation(T)if I then J[T.Name]=I:LoadAnimation(T)else print("\084\114\105\101\100 \116\111 \108\111\097\100 \097\110 \097\110\105\109 \119\105\116\104\111\117\116 \097 \104\117\109\097\110\111\105\100")end end function OnEquipped(J)G=Y.Parent I=T(G,"\072\117\109\097\110\111\105\100")Y.ChildAdded:connect(function(T)if T:IsA("\065\110\105\109\097\116\105\111\110")then LoadAnimation(animationObject)end end)for T,Y in pairs(Y:GetChildren())do if Y:IsA("\065\110\105\109\097\116\105\111\110")then LoadAnimation(Y)end end end function OnUnequipped()for T,Y in pairs(J)do StopAnimation(T)end end h.OnInvoke=PlayAnimation P.OnInvoke=StopAnimation Y.Equipped:connect(OnEquipped)Y.Unequipped:connect(OnUnequipped)

local function WaitForChild(parent, childName)
	while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
	return parent[childName]
end

local Tool = script.Parent

local Animations = {}
local MyHumanoid
local MyCharacter


local StartAnim = WaitForChild(script, 'Start')
local StopAnim = WaitForChild(script, 'Stop')


function PlayAnimation(animationName, speed)
	speed = speed or 1
	if Animations[animationName] then
		Animations[animationName]:Play(0.1, 1, speed)
	else
		print("Can't find animation:" , animationName)
	end
end

function StopAnimation(animationName)
	if Animations[animationName] then
		Animations[animationName]:Stop()
	end
end

function ConnectAnimationToValueChange(valueName, animationName)
	return WaitForChild(Tool, valueName).Changed:connect(
		function (value)
				PlayAnimation(animationName)
		end)
end

function LoadAnimation(animationObject)
	if MyHumanoid then
		Animations[animationObject.Name] = MyHumanoid:LoadAnimation(animationObject)
	else
		print("Tried to load an anim without a humanoid")
	end
end


function OnEquipped(mouse)
	MyCharacter = Tool.Parent
	MyHumanoid = WaitForChild(MyCharacter, 'Humanoid')
	
	Tool.ChildAdded:connect(function (child) if child:IsA('Animation') then LoadAnimation(animationObject) end end)
	for _, child in pairs(Tool:GetChildren()) do
		if child:IsA('Animation') then
			LoadAnimation(child)
		end
	end
end

function OnUnequipped()
	for name, animTrack in pairs(Animations) do
		StopAnimation(name);
	end
end

StartAnim.OnInvoke = PlayAnimation
StopAnim.OnInvoke = StopAnimation

Tool.Equipped:connect(OnEquipped)
Tool.Unequipped:connect(OnUnequipped)

