Tool=script.Parent Handle=Tool:WaitForChild("\072\097\110\100\108\101")Players=game:GetService("\080\108\097\121\101\114\115")UserInputService=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")Animations={}Remotes=Tool:WaitForChild("\082\101\109\111\116\101\115")ServerControl=Remotes:WaitForChild("\083\101\114\118\101\114\067\111\110\116\114\111\108")ClientControl=Remotes:WaitForChild("\067\108\105\101\110\116\067\111\110\116\114\111\108")ToolEquipped=false function SetAnimation(N,f)if not ToolEquipped or not CheckIfAlive()or not N or not f then return end if N=="\080\108\097\121\065\110\105\109\097\116\105\111\110"then for N,z in pairs(Animations)do if z.Animation==f.Animation then z.AnimationTrack:Stop()table.remove(Animations,N)end end local N=Humanoid:LoadAnimation(f.Animation)table.insert(Animations,{Animation=f.Animation;AnimationTrack=N})N:Play(f.FadeTime,f.Weight,f.Speed)elseif N=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and f then for N,z in pairs(Animations)do if z.Animation==f.Animation then z.AnimationTrack:Stop()table.remove(Animations,N)end end end end function CheckIfAlive()return(Character and(Character.Parent and(Humanoid and(Humanoid.Parent and(Humanoid.Health>0 and(Torso and(Torso.Parent and(Player and Player.Parent))))))))and true or false end function Equipped(N)Character=Tool.Parent Humanoid=Character:FindFirstChild("\072\117\109\097\110\111\105\100")Torso=Character:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")Player=Players:GetPlayerFromCharacter(Character)if not CheckIfAlive()then return end PlayerMouse=N ToolEquipped=true end function Unequipped()ToolEquipped=false for N,f in pairs(Animations)do if f and f.AnimationTrack then f.AnimationTrack:Stop()end end Animations={}end function InvokeServer(N,f)local z pcall(function()z=ServerControl:InvokeServer(N,f)end)return z end function OnClientInvoke(N,f)if not N or not ToolEquipped or not CheckIfAlive()then return end if N=="\080\108\097\121\065\110\105\109\097\116\105\111\110"then SetAnimation("\080\108\097\121\065\110\105\109\097\116\105\111\110",f)elseif N=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and f then SetAnimation("\083\116\111\112\065\110\105\109\097\116\105\111\110",f)elseif N=="\077\111\117\115\101\068\097\116\097"then return PlayerMouse and{Position=PlayerMouse.Hit.p,Target=PlayerMouse.Target}or nil 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")
UserInputService = game:GetService("UserInputService")

Animations = {}

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

ToolEquipped = false

function SetAnimation(mode, value)
	if not ToolEquipped or not CheckIfAlive() or not mode or not value then
		return
	end
	if mode == "PlayAnimation" 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 (
		(
			(
				Character
				and Character.Parent
				and Humanoid
				and Humanoid.Parent
				and Humanoid.Health > 0
				and Torso
				and Torso.Parent
				and Player
				and Player.Parent
			) and true
		) or false
	)
end

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

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

function InvokeServer(mode, value)
	local ServerReturn
	pcall(function()
		ServerReturn = ServerControl:InvokeServer(mode, value)
	end)
	return ServerReturn
end

function OnClientInvoke(mode, value)
	if not mode or not ToolEquipped or not CheckIfAlive() then
		return
	end
	if mode == "PlayAnimation" then
		SetAnimation("PlayAnimation", value)
	elseif mode == "StopAnimation" and value then
		SetAnimation("StopAnimation", value)
	elseif mode == "MouseData" then
		return ((PlayerMouse and { Position = PlayerMouse.Hit.p, Target = PlayerMouse.Target }) or nil)
	end
end

ClientControl.OnClientInvoke = OnClientInvoke

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