Tool=script.Parent Handle=Tool:WaitForChild("\072\097\110\100\108\101")Players=game:GetService("\080\108\097\121\101\114\115")Animations={}ServerControl=Tool:WaitForChild("\083\101\114\118\101\114\067\111\110\116\114\111\108")ClientControl=Tool:WaitForChild("\067\108\105\101\110\116\067\111\110\116\114\111\108")ToolEquipped=false function SetAnimation(D,n)if D=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(n and(ToolEquipped and Humanoid))then for D,X in pairs(Animations)do if X.Animation==n.Animation then X.AnimationTrack:Stop()table.remove(Animations,D)end end local D=Humanoid:LoadAnimation(n.Animation)table.insert(Animations,{Animation=n.Animation;AnimationTrack=D})D:Play(n.FadeTime,n.Weight,n.Speed)elseif D=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and n then for D,X in pairs(Animations)do if X.Animation==n.Animation then X.AnimationTrack:Stop()table.remove(Animations,D)end end end end function CheckIfAlive()return(Player and(Player.Parent and(Humanoid and(Humanoid.Parent and Humanoid.Health>0))))and true or false end function Equipped(D)Character=Tool.Parent Player=Players:GetPlayerFromCharacter(Character)Humanoid=Character:FindFirstChild("\072\117\109\097\110\111\105\100")if not CheckIfAlive()then return end ToolEquipped=true end function Unequipped()for D,n in pairs(Animations)do if n and n.AnimationTrack then n.AnimationTrack:Stop()end end Animations={}ToolEquipped=false end function InvokeServer(D,n)pcall(function()local X=ServerControl:InvokeServer(D,n)return X end)end function OnClientInvoke(D,n)if D=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(n and(ToolEquipped and Humanoid))then SetAnimation("\080\108\097\121\065\110\105\109\097\116\105\111\110",n)elseif D=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and n then SetAnimation("\083\116\111\112\065\110\105\109\097\116\105\111\110",n)elseif D=="\080\108\097\121\083\111\117\110\100"and n then n:Play()elseif D=="\083\116\111\112\083\111\117\110\100"and n then n:Stop()end end ClientControl.OnClientInvoke=OnClientInvoke Tool.Equipped:connect(Equipped)Tool.Unequipped:connect(Unequipped)
--Made by Luckymaxer

Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

Players = game:GetService("Players")

Animations = {}

ServerControl = Tool:WaitForChild("ServerControl")
ClientControl = Tool:WaitForChild("ClientControl")

ToolEquipped = false

function SetAnimation(Mode, Value)
	if Mode == "PlayAnimation" and Value and ToolEquipped and Humanoid then
		for i, v in pairs(Animations) do
			if v.Animation == Value.Animation then
				v.AnimationTrack:Stop()
				table.remove(Animations, i)
			end
		end
		local AnimationTrack = Humanoid:LoadAnimation(Value.Animation)
		table.insert(Animations, { Animation = Value.Animation, AnimationTrack = AnimationTrack })
		AnimationTrack:Play(Value.FadeTime, Value.Weight, Value.Speed)
	elseif Mode == "StopAnimation" and Value then
		for i, v in pairs(Animations) do
			if v.Animation == Value.Animation then
				v.AnimationTrack:Stop()
				table.remove(Animations, i)
			end
		end
	end
end

function CheckIfAlive()
	return (((Player and Player.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0) and true) or false)
end

function Equipped(Mouse)
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChild("Humanoid")
	if not CheckIfAlive() then
		return
	end
	ToolEquipped = true
end

function Unequipped()
	for i, v in pairs(Animations) do
		if v and v.AnimationTrack then
			v.AnimationTrack:Stop()
		end
	end
	Animations = {}
	ToolEquipped = false
end

function InvokeServer(Mode, Value)
	pcall(function()
		local ServerReturn = ServerControl:InvokeServer(Mode, Value)
		return ServerReturn
	end)
end

function OnClientInvoke(Mode, Value)
	if Mode == "PlayAnimation" and Value and ToolEquipped and Humanoid then
		SetAnimation("PlayAnimation", Value)
	elseif Mode == "StopAnimation" and Value then
		SetAnimation("StopAnimation", Value)
	elseif Mode == "PlaySound" and Value then
		Value:Play()
	elseif Mode == "StopSound" and Value then
		Value:Stop()
	end
end

ClientControl.OnClientInvoke = OnClientInvoke
Tool.Equipped:connect(Equipped)
Tool.Unequipped:connect(Unequipped)
