local r={}function WeldTool.Equip()ShowUI()EnableFocusHighlighting()end function WeldTool.Unequip()HideUI()ClearConnections()end function ClearConnections()for P,L in pairs(r)do L:disconnect()r[P]=nil end end function ShowUI()if UI then UI.Visible=true return end UI=Core.Tool.Interfaces.BTWeldToolGUI:Clone()UI.Parent=Core.UI UI.Visible=true UI.Interface.WeldButton.MouseButton1Click:connect(CreateWelds)UI.Interface.BreakWeldsButton.MouseButton1Click:connect(BreakWelds)end function HideUI()if not UI then return end UI.Visible=false end
-- Container for temporary connections (disconnected automatically)
local Connections = {}

function WeldTool.Equip()
	-- Enables the tool's equipped functionality

	-- Start up our interface
	ShowUI()
	EnableFocusHighlighting()
end

function WeldTool.Unequip()
	-- Disables the tool's equipped functionality

	-- Clear unnecessary resources
	HideUI()
	ClearConnections()
end

function ClearConnections()
	-- Clears out temporary connections

	for ConnectionKey, Connection in pairs(Connections) do
		Connection:disconnect()
		Connections[ConnectionKey] = nil
	end
end

function ShowUI()
	-- Creates and reveals the UI

	-- Reveal UI if already created
	if UI then
		-- Reveal the UI
		UI.Visible = true

		-- Skip UI creation
		return
	end

	-- Create the UI
	UI = Core.Tool.Interfaces.BTWeldToolGUI:Clone()
	UI.Parent = Core.UI
	UI.Visible = true

	-- Hook up the buttons
	UI.Interface.WeldButton.MouseButton1Click:connect(CreateWelds)
	UI.Interface.BreakWeldsButton.MouseButton1Click:connect(BreakWelds)
end

function HideUI()
	-- Hides the tool UI

	-- Make sure there's a UI
	if not UI then
		return
	end

	-- Hide the UI
	UI.Visible = false
end
