Tools.NewPart.Listeners.Equipped=function()local x=Tools.NewPart x.State.PreviousSelectionBoxColor=SelectionBoxColor SelectionBoxColor=x.Color updateSelectionBoxColor()x:showGUI()x:changeType(x.Options.type)end Tools.NewPart.Listeners.Unequipped=function()local x=Tools.NewPart x:hideGUI()for U,E in pairs(x.Connections)do E:disconnect()x.Connections[U]=nil end SelectionBoxColor=x.State.PreviousSelectionBoxColor updateSelectionBoxColor()end Tools.NewPart.Listeners.Button1Down=function()local x=Tools.NewPart local U if x.Options.type=="\110\111\114\109\097\108"then U=Instance.new("\080\097\114\116",Services.Workspace)U.FormFactor="\067\117\115\116\111\109"U.Size=Vector3.new(4,1,2)elseif x.Options.type=="\116\114\117\115\115"then U=Instance.new("\084\114\117\115\115\080\097\114\116",Services.Workspace)elseif x.Options.type=="\119\101\100\103\101"then U=Instance.new("\087\101\100\103\101\080\097\114\116",Services.Workspace)elseif x.Options.type=="\099\111\114\110\101\114"then U=Instance.new("\067\111\114\110\101\114\087\101\100\103\101\080\097\114\116",Services.Workspace)elseif x.Options.type=="\099\121\108\105\110\100\101\114"then U=Instance.new("\080\097\114\116",Services.Workspace)U.Shape="\067\121\108\105\110\100\101\114"elseif x.Options.type=="\098\097\108\108"then U=Instance.new("\080\097\114\116",Services.Workspace)U.Shape="\066\097\108\108"elseif x.Options.type=="\115\101\097\116"then U=Instance.new("\083\101\097\116",Services.Workspace)elseif x.Options.type=="\118\101\104\105\099\108\101 \115\101\097\116"then U=Instance.new("\086\101\104\105\099\108\101\083\101\097\116",Services.Workspace)elseif x.Options.type=="\115\112\097\119\110"then U=Instance.new("\083\112\097\119\110\076\111\099\097\116\105\111\110",Services.Workspace)end U.Anchored=true Selection:clear()Selection:add(U)local E={target=U;apply=function(x)Selection:clear()if x.target then x.target.Parent=Services.Workspace Selection:add(x.target)end end;unapply=function(x)if x.target then x.target.Parent=nil end end}History:add(E)equipTool(Tools.Move)Tools.Move.ManualTarget=U U.CFrame=CFrame.new(Mouse.Hit.p)Tools.Move.Listeners.Button1Down()Tools.Move.Listeners.Move()end Tools.NewPart.changeType=function(x,U)x.Options.type=U x.TypeDropdown:selectOption(U:upper())if x.TypeDropdown.open then x.TypeDropdown:toggle()end end Tools.NewPart.showGUI=function(x)if not x.GUI then local U=Tool.Interfaces.BTNewPartToolGUI:Clone()U.Parent=UI local E=createDropdown()x.TypeDropdown=E E.Frame.Parent=U.TypeOption E.Frame.Position=UDim2.new(0,70,0,0)E.Frame.Size=UDim2.new(0,140,0,25);(E:addOption("\078\079\082\077\065\076")).MouseButton1Up:connect(function()x:changeType("\110\111\114\109\097\108")end);(E:addOption("\084\082\085\083\083")).MouseButton1Up:connect(function()x:changeType("\116\114\117\115\115")end);(E:addOption("\087\069\068\071\069")).MouseButton1Up:connect(function()x:changeType("\119\101\100\103\101")end);(E:addOption("\067\079\082\078\069\082")).MouseButton1Up:connect(function()x:changeType("\099\111\114\110\101\114")end);(E:addOption("\067\089\076\073\078\068\069\082")).MouseButton1Up:connect(function()x:changeType("\099\121\108\105\110\100\101\114")end);(E:addOption("\066\065\076\076")).MouseButton1Up:connect(function()x:changeType("\098\097\108\108")end);(E:addOption("\083\069\065\084")).MouseButton1Up:connect(function()x:changeType("\115\101\097\116")end);(E:addOption("\086\069\072\073\067\076\069 \083\069\065\084")).MouseButton1Up:connect(function()x:changeType("\118\101\104\105\099\108\101 \115\101\097\116")end);(E:addOption("\083\080\065\087\078")).MouseButton1Up:connect(function()x:changeType("\115\112\097\119\110")end)x.GUI=U end x.GUI.Visible=true end Tools.NewPart.hideGUI=function(x)if x.GUI then x.GUI.Visible=false end end Tools.NewPart.Loaded=true

Tools.NewPart.Listeners.Equipped = function ()

	local self = Tools.NewPart;

	-- Change the color of selection boxes temporarily
	self.State.PreviousSelectionBoxColor = SelectionBoxColor;
	SelectionBoxColor = self.Color;
	updateSelectionBoxColor();

	-- Reveal the GUI
	self:showGUI();

	-- Restore the type option
	self:changeType( self.Options.type );

end;

Tools.NewPart.Listeners.Unequipped = function ()

	local self = Tools.NewPart;

	-- Hide the GUI
	self:hideGUI();

	-- Disconnect temporary connections
	for connection_index, Connection in pairs( self.Connections ) do
		Connection:disconnect();
		self.Connections[connection_index] = nil;
	end;

	-- Restore the original color of selection boxes
	SelectionBoxColor = self.State.PreviousSelectionBoxColor;
	updateSelectionBoxColor();

end;

Tools.NewPart.Listeners.Button1Down = function ()

	local self = Tools.NewPart;

	local NewPart;

	-- Create the new part of type `self.Options.type`
	if self.Options.type == "normal" then
		NewPart = Instance.new( "Part", Services.Workspace );
		NewPart.FormFactor = "Custom";
		NewPart.Size = Vector3.new( 4, 1, 2 );
	elseif self.Options.type == "truss" then
		NewPart = Instance.new( "TrussPart", Services.Workspace );
	elseif self.Options.type == "wedge" then
		NewPart = Instance.new( "WedgePart", Services.Workspace );
	elseif self.Options.type == "corner" then
		NewPart = Instance.new( "CornerWedgePart", Services.Workspace );
	elseif self.Options.type == "cylinder" then
		NewPart = Instance.new( "Part", Services.Workspace );
		NewPart.Shape = "Cylinder";
	elseif self.Options.type == "ball" then
		NewPart = Instance.new( "Part", Services.Workspace );
		NewPart.Shape = "Ball";
	elseif self.Options.type == "seat" then
		NewPart = Instance.new( "Seat", Services.Workspace );
	elseif self.Options.type == "vehicle seat" then
		NewPart = Instance.new( "VehicleSeat", Services.Workspace );
	elseif self.Options.type == "spawn" then
		NewPart = Instance.new( "SpawnLocation", Services.Workspace );
	end;
	NewPart.Anchored = true;

	-- Select the new part
	Selection:clear();
	Selection:add( NewPart );

	local HistoryRecord = {
		target = NewPart;
		apply = function ( self )
			Selection:clear();
			if self.target then
				self.target.Parent = Services.Workspace;
				Selection:add( self.target );
			end;
		end;
		unapply = function ( self )
			if self.target then
				self.target.Parent = nil;
			end;
		end;
	};
	History:add( HistoryRecord );

	-- Switch to the move tool and simulate clicking so
	-- that the user could easily position their new part
	equipTool( Tools.Move );
	Tools.Move.ManualTarget = NewPart;
	NewPart.CFrame = CFrame.new( Mouse.Hit.p );
	Tools.Move.Listeners.Button1Down();
	Tools.Move.Listeners.Move();

end;

Tools.NewPart.changeType = function ( self, new_type )
	self.Options.type = new_type;
	self.TypeDropdown:selectOption( new_type:upper() );
	if self.TypeDropdown.open then
		self.TypeDropdown:toggle();
	end;
end;

Tools.NewPart.showGUI = function ( self )

	-- Initialize the GUI if it's not ready yet
	if not self.GUI then

		local Container = Tool.Interfaces.BTNewPartToolGUI:Clone();
		Container.Parent = UI;

		local TypeDropdown = createDropdown();
		self.TypeDropdown = TypeDropdown;
		TypeDropdown.Frame.Parent = Container.TypeOption;
		TypeDropdown.Frame.Position = UDim2.new( 0, 70, 0, 0 );
		TypeDropdown.Frame.Size = UDim2.new( 0, 140, 0, 25 );

		TypeDropdown:addOption( "NORMAL" ).MouseButton1Up:connect( function ()
			self:changeType( "normal" );
		end );
		TypeDropdown:addOption( "TRUSS" ).MouseButton1Up:connect( function ()
			self:changeType( "truss" );
		end );
		TypeDropdown:addOption( "WEDGE" ).MouseButton1Up:connect( function ()
			self:changeType( "wedge" );
		end );
		TypeDropdown:addOption( "CORNER" ).MouseButton1Up:connect( function ()
			self:changeType( "corner" );
		end );
		TypeDropdown:addOption( "CYLINDER" ).MouseButton1Up:connect( function ()
			self:changeType( "cylinder" );
		end );
		TypeDropdown:addOption( "BALL" ).MouseButton1Up:connect( function ()
			self:changeType( "ball" );
		end );
		TypeDropdown:addOption( "SEAT" ).MouseButton1Up:connect( function ()
			self:changeType( "seat" );
		end );
		TypeDropdown:addOption( "VEHICLE SEAT" ).MouseButton1Up:connect( function ()
			self:changeType( "vehicle seat" );
		end );
		TypeDropdown:addOption( "SPAWN" ).MouseButton1Up:connect( function ()
			self:changeType( "spawn" );
		end );

		self.GUI = Container;
	end;

	-- Reveal the GUI
	self.GUI.Visible = true;

end;

Tools.NewPart.hideGUI = function ( self )

	-- Hide the GUI if it exists already
	if self.GUI then
		self.GUI.Visible = false;
	end;

end;

Tools.NewPart.Loaded = true;
