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(y,J)if y=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(J and(ToolEquipped and Humanoid))then for y,K in pairs(Animations)do if K.Animation==J.Animation then K.AnimationTrack:Stop()table.remove(Animations,y)end end local y=Humanoid:LoadAnimation(J.Animation)table.insert(Animations,{Animation=J.Animation,AnimationTrack=y})y:Play(J.FadeTime,J.Weight,J.Speed)elseif y=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and J then for y,K in pairs(Animations)do if K.Animation==J.Animation then K.AnimationTrack:Stop()table.remove(Animations,y)end end end 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(y)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=Player:GetMouse()y.Button1Down:connect(function()InvokeServer("\077\111\117\115\101\067\108\105\099\107",{Down=true})end)y.Button1Up:connect(function()InvokeServer("\077\111\117\115\101\067\108\105\099\107",{Down=false})end)y.KeyDown:connect(function(y)InvokeServer("\075\101\121\080\114\101\115\115",{Key=y;Down=true})end)y.KeyUp:connect(function(y)InvokeServer("\075\101\121\080\114\101\115\115",{Key=y,Down=false})end)y.Move:connect(function()InvokeServer("\077\111\117\115\101\077\111\118\101",{Position=y.Hit.p;Target=y.Target})end)end function Unequipped()Animations={}ToolEquipped=false end function InvokeServer(y,J)pcall(function()local K=ServerControl:InvokeServer(y,J)return K end)end function OnClientInvoke(y,J)if y=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(J and(ToolEquipped and Humanoid))then SetAnimation("\080\108\097\121\065\110\105\109\097\116\105\111\110",J)elseif y=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and J then SetAnimation("\083\116\111\112\065\110\105\109\097\116\105\111\110",J)elseif y=="\080\108\097\121\083\111\117\110\100"and J then J:Play()elseif y=="\083\116\111\112\083\111\117\110\100"and J then J:Stop()elseif y=="\077\111\117\115\101\080\111\115\105\116\105\111\110"then return{Position=PlayerMouse.Hit.p,Target=PlayerMouse.Target}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 (
		(
			(
				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 = Player:GetMouse()
	Mouse.Button1Down:connect(function()
		InvokeServer("MouseClick", { Down = true })
	end)
	Mouse.Button1Up:connect(function()
		InvokeServer("MouseClick", { Down = false })
	end)
	Mouse.KeyDown:connect(function(Key)
		InvokeServer("KeyPress", { Key = Key, Down = true })
	end)
	Mouse.KeyUp:connect(function(Key)
		InvokeServer("KeyPress", { Key = Key, Down = false })
	end)
	Mouse.Move:connect(function()
		InvokeServer("MouseMove", { Position = Mouse.Hit.p, Target = Mouse.Target })
	end)
end

function Unequipped()
	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()
	elseif mode == "MousePosition" then
		return { Position = PlayerMouse.Hit.p, Target = PlayerMouse.Target }
	end
end

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