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")UserInputService=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")Animations={}LocalObjects={}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")InputCheck=Instance.new("\083\099\114\101\101\110\071\117\105")InputCheck.Name="\073\110\112\117\116\067\104\101\099\107"InputButton=Instance.new("\073\109\097\103\101\066\117\116\116\111\110")InputButton.Name="\073\110\112\117\116\066\117\116\116\111\110"InputButton.Image=""InputButton.BackgroundTransparency=1 InputButton.ImageTransparency=1 InputButton.Size=UDim2.new(1,0,1,0)InputButton.Parent=InputCheck Rate=.016666666666667 ToolEquipped=false function SetAnimation(M,B)if M=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(B and(ToolEquipped and Humanoid))then for M,S in pairs(Animations)do if S.Animation==B.Animation then S.AnimationTrack:Stop()table.remove(Animations,M)end end local M=Humanoid:LoadAnimation(B.Animation)table.insert(Animations,{Animation=B.Animation,AnimationTrack=M})M:Play(B.FadeTime,B.Weight,B.Speed)elseif M=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and B then for M,S in pairs(Animations)do if S.Animation==B.Animation then S.AnimationTrack:Stop(B.FadeTime)table.remove(Animations,M)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(M)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()M.Button1Down:connect(function()InvokeServer("\066\117\116\116\111\110\049\067\108\105\099\107",{Down=true})end)M.Button1Up:connect(function()InvokeServer("\066\117\116\116\111\110\049\067\108\105\099\107",{Down=false})end)local B=Player:FindFirstChild("\080\108\097\121\101\114\071\117\105")if B then if UserInputService.TouchEnabled then InputCheckClone=InputCheck:Clone()InputCheckClone.InputButton.InputBegan:connect(function()InvokeServer("\066\117\116\116\111\110\049\067\108\105\099\107",{Down=true})end)InputCheckClone.InputButton.InputEnded:connect(function()InvokeServer("\066\117\116\116\111\110\049\067\108\105\099\107",{Down=false})end)InputCheckClone.Parent=B end end end)end function Unequipped()LocalObjects={}if InputCheckClone and InputCheckClone.Parent then InputCheckClone:Destroy()end for M,B in pairs(Animations)do if B and B.AnimationTrack then B.AnimationTrack:Stop()end end for M,B in pairs({ObjectLocalTransparencyModifier})do if B then B:disconnect()end end Animations={}ToolEquipped=false end function InvokeServer(M,B)pcall(function()local S=ServerControl:InvokeServer(M,B)return S end)end function OnClientInvoke(M,B)if M=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(B and(ToolEquipped and Humanoid))then SetAnimation("\080\108\097\121\065\110\105\109\097\116\105\111\110",B)elseif M=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and B then SetAnimation("\083\116\111\112\065\110\105\109\097\116\105\111\110",B)elseif M=="\080\108\097\121\083\111\117\110\100"and B then B:Play()elseif M=="\083\116\111\112\083\111\117\110\100"and B then B:Stop()elseif M=="\077\111\117\115\101\080\111\115\105\116\105\111\110"then if not PlayerMouse and CheckIfAlive()then PlayerMouse=Player:GetMouse()end return{Position=PlayerMouse.Hit.p,Target=PlayerMouse.Target}elseif M=="\083\101\116\076\111\099\097\108\084\114\097\110\115\112\097\114\101\110\099\121\077\111\100\105\102\105\101\114"and(B and ToolEquipped)then pcall(function()local M=false for S,q in pairs(LocalObjects)do if q==B then M=true end end if not M then table.insert(LocalObjects,B)if ObjectLocalTransparencyModifier then ObjectLocalTransparencyModifier:disconnect()end ObjectLocalTransparencyModifier=RunService.RenderStepped:connect(function()for M,B in pairs(LocalObjects)do if B.Object and B.Object.Parent then local M=B.Object.LocalTransparencyModifier if not B.AutoUpdate and(M==1 or M==0)or B.AutoUpdate then B.Object.LocalTransparencyModifier=B.Transparency end else table.remove(LocalObjects,M)end end end)end end)end end ClientControl.OnClientInvoke=OnClientInvoke Tool.Equipped:connect(Equipped)Tool.Unequipped:connect(Unequipped)


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

Players = game:GetService("Players")
RunService = game:GetService("RunService")
UserInputService = game:GetService("UserInputService")

Animations = {}
LocalObjects = {}

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

InputCheck = Instance.new("ScreenGui")
InputCheck.Name = "InputCheck"
InputButton = Instance.new("ImageButton")
InputButton.Name = "InputButton"
InputButton.Image = ""
InputButton.BackgroundTransparency = 1
InputButton.ImageTransparency = 1
InputButton.Size = UDim2.new(1, 0, 1, 0)
InputButton.Parent = InputCheck

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 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)
		local PlayerGui = Player:FindFirstChild("PlayerGui")
		if PlayerGui then
			if UserInputService.TouchEnabled then
				InputCheckClone = InputCheck:Clone()
				InputCheckClone.InputButton.InputBegan:connect(function()
					InvokeServer("Button1Click", {Down = true})
				end)
				InputCheckClone.InputButton.InputEnded:connect(function()
					InvokeServer("Button1Click", {Down = false})
				end)
				InputCheckClone.Parent = PlayerGui
			end
		end
	end)
end

function Unequipped()
	LocalObjects = {}
	if InputCheckClone and InputCheckClone.Parent then
		InputCheckClone:Destroy()
	end
	for i, v in pairs(Animations) do
		if v and v.AnimationTrack then
			v.AnimationTrack:Stop()
		end
	end
	for i, v in pairs({ObjectLocalTransparencyModifier}) do
		if v then
			v:disconnect()
		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()
	elseif mode == "MousePosition" then
		if not PlayerMouse and CheckIfAlive() then
			PlayerMouse = Player:GetMouse()
		end
		return {Position = PlayerMouse.Hit.p, Target = PlayerMouse.Target}
	elseif mode == "SetLocalTransparencyModifier" and value and ToolEquipped then
		pcall(function()
			local ObjectFound = false
			for i, v in pairs(LocalObjects) do
				if v == value then
					ObjectFound = true
				end
			end
			if not ObjectFound then
				table.insert(LocalObjects, value)
				if ObjectLocalTransparencyModifier then
					ObjectLocalTransparencyModifier:disconnect()
				end
				ObjectLocalTransparencyModifier = RunService.RenderStepped:connect(function()
					for i, v in pairs(LocalObjects) do
						if v.Object and v.Object.Parent then
							local CurrentTransparency = v.Object.LocalTransparencyModifier
							if ((not v.AutoUpdate and (CurrentTransparency == 1 or  CurrentTransparency == 0)) or v.AutoUpdate) then
								v.Object.LocalTransparencyModifier = v.Transparency
							end
						else
							table.remove(LocalObjects, i)
						end
					end
				end)
			end
		end)
	end
end

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