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

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)
	Humanoid:ChangeState(Enum.HumanoidStateType.None)
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
	Humanoid:ChangeState(Enum.HumanoidStateType.Freefall) --Prevent the ability to fly by constantly equipping and unequipping the tool.
	Animations = {}
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}
	elseif mode == "DisableJump" then
		DisableJump(value)
	elseif mode == "Preload" and value then
		ContentProvider:Preload(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)
