local function V(V,E)while not V:FindFirstChild(E)do V.ChildAdded:wait()end return V[E]end local E=script.Parent local s={}local t local H local function Y(V)if s[V]then s[V]:Play()end end local function h(V)if s[V]then s[V]:Stop()end end function OnEquipped(h)H=E.Parent t=V(H,"\072\117\109\097\110\111\105\100")if t then s.IdleAnim=t:LoadAnimation(V(E,"\073\100\108\101"))end Y("\073\100\108\101\065\110\105\109")end function OnUnequipped()for V,E in pairs(s)do h(V)end end E.Equipped:connect(OnEquipped)E.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 function PlayAnimation(animationName)
	if Animations[animationName] then
		Animations[animationName]:Play()
	end
end

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


function OnEquipped(mouse)
	MyCharacter = Tool.Parent
	MyHumanoid = WaitForChild(MyCharacter, 'Humanoid')
	if MyHumanoid then
		Animations['IdleAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'Idle'))
	end
	PlayAnimation('IdleAnim')
end

function OnUnequipped()
	for animName, _ in pairs(Animations) do
		StopAnimation(animName)
	end
end

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