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

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

ToolEquipped = false

function SetAnimation(mode, value)
	if not ToolEquipped or not CheckIfAlive() then
		return
	end
	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 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 Head and Head.Parent and Player and Player.Parent) and true) or false)
end

function Equipped(Mouse)
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChild("Humanoid")
	Head = Character:FindFirstChild("Head")
	ToolEquipped = true
	if not CheckIfAlive() then
		return
	end
	PlayerMouse = Player:GetMouse()
	Mouse.KeyDown:connect(function(Key)
		InvokeServer("KeyPress", {Key = Key, Down = true})
	end)
	Mouse.KeyUp:connect(function(Key)
		InvokeServer("KeyPress", {Key = Key, Down = false})
	end)
end

function Unequipped()
	ToolEquipped = false
	for i, v in pairs(Animations) do
		if v and v.AnimationTrack then
			v.AnimationTrack:Stop()
		end
	end
	for i, v in pairs(LocalObjects) do
		if v.Object then
			v.Object.LocalTransparencyModifier = 0
		end
	end
	for i, v in pairs({PreventJump, ObjectLocalTransparencyModifier}) do
		if v then
			v:disconnect()
		end
	end
	Animations = {}
	LocalObjects = {}
end

function InvokeServer(mode, value)
	local ServerReturn
	pcall(function()
		ServerReturn = ServerControl:InvokeServer(mode, value)
	end)
	return ServerReturn
end

function OnClientInvoke(mode, value)
	if not ToolEquipped or not CheckIfAlive() or not mode then
		return
	end
	if mode == "PlayAnimation" and value 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 {Position = PlayerMouse.Hit.p, Target = PlayerMouse.Target}
	elseif mode == "DisableJump" then
		DisableJump(value)
	elseif mode == "SetLocalTransparencyModifier" and value 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()
					local Camera = game:GetService("Workspace").CurrentCamera
					for i, v in pairs(LocalObjects) do
						if v.Object and v.Object.Parent then
							local CurrentTransparency = v.Object.LocalTransparencyModifier
							local ViewDistance = (Camera.CoordinateFrame.p - Head.Position).Magnitude
							if ((not v.AutoUpdate and (CurrentTransparency == 1 or CurrentTransparency == 0)) or v.AutoUpdate) then
								if ((v.Distance and ViewDistance <= v.Distance) or not v.Distance) then
									v.Object.LocalTransparencyModifier = v.Transparency
								else
									v.Object.LocalTransparencyModifier = 0
								end
							end
						else
							table.remove(LocalObjects, i)
						end
					end
				end)
			end
		end)
	end
end

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