Tool=script.Parent Handle=Tool:WaitForChild("\072\097\110\100\108\101")Players=game:GetService("\080\108\097\121\101\114\115")RunService=game:GetService("\082\117\110\083\101\114\118\105\099\101")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")Rate=.016666666666667 ToolEquipped=false function SetAnimation(R,x)if R=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(x and(ToolEquipped and Humanoid))then for R,K in pairs(Animations)do if K.Animation==x.Animation then K.AnimationTrack:Stop()table.remove(Animations,R)end end local R=Humanoid:LoadAnimation(x.Animation)table.insert(Animations,{Animation=x.Animation;AnimationTrack=R})R:Play(x.FadeTime,x.Weight,x.Speed)elseif R=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and x then for R,K in pairs(Animations)do if K.Animation==x.Animation then K.AnimationTrack:Stop(x.FadeTime)table.remove(Animations,R)end end end end function KeyPressed(R,x)InvokeServer("\075\101\121\080\114\101\115\115\101\100",{Key=R,Down=x})end function CheckIfAlive()return(Character and(Character.Parent and(Humanoid and(Humanoid.Parent and(Humanoid.Health>0 and(Player and Player.Parent))))))and true or false end function Equipped(R)Character=Tool.Parent Player=Players:GetPlayerFromCharacter(Character)Humanoid=Character:FindFirstChild("\072\117\109\097\110\111\105\100")ToolEquipped=true if not CheckIfAlive()then return end PlayerMouse=R PlayerMouse.KeyDown:connect(function(R)KeyPressed(R,true)end)PlayerMouse.KeyUp:connect(function(R)KeyPressed(R,false)end)end function Unequipped()for R,x in pairs(Animations)do if x and x.AnimationTrack then x.AnimationTrack:Stop()end end Animations={}ToolEquipped=false end function InvokeServer(R,x)local K pcall(function()K=ServerControl:InvokeServer(R,x)end)return K end function OnClientInvoke(R,x)if R=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(x and(ToolEquipped and Humanoid))then SetAnimation("\080\108\097\121\065\110\105\109\097\116\105\111\110",x)elseif R=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and x then SetAnimation("\083\116\111\112\065\110\105\109\097\116\105\111\110",x)elseif R=="\080\108\097\121\083\111\117\110\100"and x then x:Play()elseif R=="\083\116\111\112\083\111\117\110\100"and x then x:Stop()elseif R=="\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")
RunService = game:GetService("RunService")

Animations = {}

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

Rate = (1 / 60)

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(value.FadeTime)
				table.remove(Animations, i)
			end
		end
	end
end

function KeyPressed(Key, Down)
	InvokeServer("KeyPressed", { Key = Key, Down = Down })
end

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

function Equipped(Mouse)
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChild("Humanoid")
	ToolEquipped = true
	if not CheckIfAlive() then
		return
	end
	PlayerMouse = Mouse
	PlayerMouse.KeyDown:connect(function(Key)
		KeyPressed(Key, true)
	end)
	PlayerMouse.KeyUp:connect(function(Key)
		KeyPressed(Key, false)
	end)
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)
	local ServerReturn
	pcall(function()
		ServerReturn = ServerControl:InvokeServer(mode, value)
	end)
	return ServerReturn
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()
	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)
