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")Camera=(game:GetService("\087\111\114\107\115\112\097\099\101")).CurrentCamera 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")ToolEquipped=false function SetAnimation(C,l)if C=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(l and(ToolEquipped and Humanoid))then for C,x in pairs(Animations)do if x.Animation==l.Animation then x.AnimationTrack:Stop()table.remove(Animations,C)end end local C=Humanoid:LoadAnimation(l.Animation)table.insert(Animations,{Animation=l.Animation,AnimationTrack=C})C:Play(l.FadeTime,l.Weight,l.Speed)elseif C=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and l then for C,x in pairs(Animations)do if x.Animation==l.Animation then x.AnimationTrack:Stop()table.remove(Animations,C)end end end end function DisableJump(C)if PreventJump then PreventJump:disconnect()end if C then PreventJump=Humanoid.Changed:connect(function(C)if C=="\074\117\109\112"then Humanoid.Jump=false 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(C)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()C.Button1Down:connect(function()InvokeServer("\077\111\117\115\101\067\108\105\099\107",{Down=true})end)C.Button1Up:connect(function()InvokeServer("\077\111\117\115\101\067\108\105\099\107",{Down=false})end)C.KeyDown:connect(function(C)InvokeServer("\075\101\121\080\114\101\115\115",{Key=C;Down=true})end)C.KeyUp:connect(function(C)InvokeServer("\075\101\121\080\114\101\115\115",{Key=C,Down=false})end)C.Move:connect(function()InvokeServer("\077\111\117\115\101\077\111\118\101",{Position=C.Hit.p,Target=C.Target})end)end function Unequipped()ToolEquipped=false LocalObjects={}for C,l in pairs(Animations)do if l and l.AnimationTrack then l.AnimationTrack:Stop()end end for C,l in pairs({PreventJump;ObjectLocalTransparencyModifier})do if l then l:disconnect()end end Animations={}end function InvokeServer(C,l)local x pcall(function()x=ServerControl:InvokeServer(C,l)end)return x end function OnClientInvoke(C,l)if C=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(l and(ToolEquipped and Humanoid))then SetAnimation("\080\108\097\121\065\110\105\109\097\116\105\111\110",l)elseif C=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and l then SetAnimation("\083\116\111\112\065\110\105\109\097\116\105\111\110",l)elseif C=="\080\108\097\121\083\111\117\110\100"and l then l:Play()elseif C=="\083\116\111\112\083\111\117\110\100"and l then l:Stop()elseif C=="\077\111\117\115\101\080\111\115\105\116\105\111\110"then return{Position=PlayerMouse.Hit.p;Target=PlayerMouse.Target}elseif C=="\068\105\115\097\098\108\101\074\117\109\112"then DisableJump(l)elseif C=="\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(l and ToolEquipped)then pcall(function()local C=false for x,p in pairs(LocalObjects)do if p==l then C=true end end if not C then table.insert(LocalObjects,l)if ObjectLocalTransparencyModifier then ObjectLocalTransparencyModifier:disconnect()end ObjectLocalTransparencyModifier=RunService.RenderStepped:connect(function()for C,l in pairs(LocalObjects)do if l.Object and l.Object.Parent then local C=l.Object.LocalTransparencyModifier if not l.AutoUpdate and(C==1 or C==0)or l.AutoUpdate then l.Object.LocalTransparencyModifier=l.Transparency end else table.remove(LocalObjects,C)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")

Camera = game:GetService("Workspace").CurrentCamera

Animations = {}
LocalObjects = {}

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 DisableJump(Boolean)
	if PreventJump then
		PreventJump:disconnect()
	end
	if Boolean then
		PreventJump = Humanoid.Changed:connect(function(Property)
			if Property ==  "Jump" then
				Humanoid.Jump = false
			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()
	ToolEquipped = false
	LocalObjects = {}
	for i, v in pairs(Animations) do
		if v and v.AnimationTrack then
			v.AnimationTrack:Stop()
		end
	end
	for i, v in pairs({PreventJump, ObjectLocalTransparencyModifier}) do
		if v then
			v:disconnect()
		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 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}
	elseif mode == "DisableJump" then
		DisableJump(value)
	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)
