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")ContentProvider=game:GetService("\067\111\110\116\101\110\116\080\114\111\118\105\100\101\114")RbxUtility=LoadLibrary("\082\098\120\085\116\105\108\105\116\121")Create=RbxUtility.Create 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(V,c)if not ToolEquipped or not CheckIfAlive()then return end local function t(V)for t,s in pairs(Animations)do if s.Animation==V then s.AnimationTrack:Stop(c.EndFadeTime)if s.TrackStopped then s.TrackStopped:disconnect()end table.remove(Animations,t)end end end if V=="\080\108\097\121\065\110\105\109\097\116\105\111\110"then for V,s in pairs(Animations)do if s.Animation==c.Animation then if c.Speed then s.AnimationTrack:AdjustSpeed(c.Speed)return elseif c.Weight or c.FadeTime then s.AnimationTrack:AdjustWeight(c.Weight,c.FadeTime)return else t(c.Animation,false)end end end local V=(Create("\077\111\100\101\108"))({})local s=(Create("\083\116\114\105\110\103\086\097\108\117\101"))({Name="\069\110\100\101\100"})local h=Humanoid:LoadAnimation(c.Animation)local p if not c.Manual then p=h.Stopped:connect(function()if p then p:disconnect()end t(c.Animation,true)s.Parent=V end)end table.insert(Animations,{Animation=c.Animation,AnimationTrack=h;TrackStopped=p})h:Play(c.FadeTime,c.Weight,c.Speed)if p then V:WaitForChild(s.Name)end return s.Name elseif V=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and c then t(c.Animation)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(V)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 Spawn(function()PlayerMouse=Player:GetMouse()V.Button1Down:connect(function()InvokeServer("\066\117\116\116\111\110\049\067\108\105\099\107",{Down=true})end)V.Button1Up:connect(function()InvokeServer("\066\117\116\116\111\110\049\067\108\105\099\107",{Down=false})end)V.KeyDown:connect(function(V)InvokeServer("\075\101\121\080\114\101\115\115",{Key=V;Down=true})end)V.KeyUp:connect(function(V)InvokeServer("\075\101\121\080\114\101\115\115",{Key=V,Down=false})end)for V,c in pairs(Tool:GetChildren())do if c:IsA("\065\110\105\109\097\116\105\111\110")then ContentProvider:Preload(c.AnimationId)end end end)end function Unequipped()for V,c in pairs(Animations)do if c and c.AnimationTrack then c.AnimationTrack:Stop()end end Animations={}ToolEquipped=false end function InvokeServer(V,c)local t=nil pcall(function()t=ServerControl:InvokeServer(V,c)end)return t end function OnClientInvoke(V,c)if V=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(c and(ToolEquipped and Humanoid))then SetAnimation("\080\108\097\121\065\110\105\109\097\116\105\111\110",c)elseif V=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and c then SetAnimation("\083\116\111\112\065\110\105\109\097\116\105\111\110",c)elseif V=="\080\108\097\121\083\111\117\110\100"and c then c:Play()elseif V=="\083\116\111\112\083\111\117\110\100"and c then c:Stop()elseif V=="\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")
RunService = game:GetService("RunService")
ContentProvider = game:GetService("ContentProvider")

RbxUtility = LoadLibrary("RbxUtility")
Create = RbxUtility.Create

Animations = {}

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

Rate = (1 / 60)

ToolEquipped = false

function SetAnimation(mode, value)
	if not ToolEquipped or not CheckIfAlive() then
		return
	end
	local function StopAnimation(Animation)
		for i, v in pairs(Animations) do
			if v.Animation == Animation then
				v.AnimationTrack:Stop(value.EndFadeTime)
				if v.TrackStopped then
					v.TrackStopped:disconnect()
				end
				table.remove(Animations, i)
			end
		end
	end
	if mode == "PlayAnimation" then
		for i, v in pairs(Animations) do
			if v.Animation == value.Animation then
				if value.Speed then
					v.AnimationTrack:AdjustSpeed(value.Speed)
					return
				elseif value.Weight or value.FadeTime then
					v.AnimationTrack:AdjustWeight(value.Weight, value.FadeTime)
					return
				else
					StopAnimation(value.Animation, false)
				end
			end
		end
		local AnimationMonitor = Create("Model")({})
		local TrackEnded = Create("StringValue")({ Name = "Ended" })
		local AnimationTrack = Humanoid:LoadAnimation(value.Animation)
		local TrackStopped
		if not value.Manual then
			TrackStopped = AnimationTrack.Stopped:connect(function()
				if TrackStopped then
					TrackStopped:disconnect()
				end
				StopAnimation(value.Animation, true)
				TrackEnded.Parent = AnimationMonitor
			end)
		end
		table.insert(
			Animations,
			{ Animation = value.Animation, AnimationTrack = AnimationTrack, TrackStopped = TrackStopped }
		)
		AnimationTrack:Play(value.FadeTime, value.Weight, value.Speed)
		if TrackStopped then
			AnimationMonitor:WaitForChild(TrackEnded.Name)
		end
		return TrackEnded.Name
	elseif mode == "StopAnimation" and value then
		StopAnimation(value.Animation)
	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
	Spawn(function()
		PlayerMouse = Player:GetMouse()
		Mouse.Button1Down:connect(function()
			InvokeServer("Button1Click", { Down = true })
		end)
		Mouse.Button1Up:connect(function()
			InvokeServer("Button1Click", { 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)
		for i, v in pairs(Tool:GetChildren()) do
			if v:IsA("Animation") then
				ContentProvider:Preload(v.AnimationId)
			end
		end
	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 = nil
	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 == "MousePosition" then
		return { Position = PlayerMouse.Hit.p, Target = PlayerMouse.Target }
	end
end

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