local function g(g,e)while not g:FindFirstChild(e)do g.ChildAdded:wait()end return g[e]end local e=script.Parent local V={}local y local b local function p(g)if V[g]then V[g]:Play()end end local function M(g)if V[g]then V[g]:Stop()end end function OnEquipped(M)b=e.Parent y=g(b,"\072\117\109\097\110\111\105\100")if y then V.IdleAnim=y:LoadAnimation(g(e,"\073\100\108\101"))end p("\073\100\108\101\065\110\105\109")end function OnUnequipped()for g,e in pairs(V)do M(g)end end e.Equipped:connect(OnEquipped)e.Unequipped:connect(OnUnequipped)
-- Waits for the child of the specified parent
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)
