local G=Support.FlipTable({"\087\101\108\100";"\077\097\110\117\097\108\087\101\108\100";"\077\097\110\117\097\108\071\108\117\101","\077\111\116\111\114","\077\111\116\111\114\054\068"})function SearchJoints(R,d,q)local E={}for R,d in pairs(GetChildren(R))do if G[d.ClassName]and(q[d.Part0]and q[d.Part1])then E[d]=d.Parent end end return E end function RestoreJoints(G)for G,R in pairs(G)do G.Parent=R end end function PreserveJoints(G,R)local d=GetPartJoints(G,R)for G in pairs(d)do G.Parent=nil end return d end function CreatePart(G)local R if G=="\078\111\114\109\097\108"then R=Instance.new("\080\097\114\116")R.Size=Vector3.new(4,1,2)elseif G=="\084\114\117\115\115"then R=Instance.new("\084\114\117\115\115\080\097\114\116")elseif G=="\087\101\100\103\101"then R=Instance.new("\087\101\100\103\101\080\097\114\116")R.Size=Vector3.new(4,1,2)elseif G=="\067\111\114\110\101\114"then R=Instance.new("\067\111\114\110\101\114\087\101\100\103\101\080\097\114\116")elseif G=="\067\121\108\105\110\100\101\114"then R=Instance.new("\080\097\114\116")R.Shape="\067\121\108\105\110\100\101\114"R.Size=Vector3.new(2,2,2)elseif G=="\066\097\108\108"then R=Instance.new("\080\097\114\116")R.Shape="\066\097\108\108"elseif G=="\083\101\097\116"then R=Instance.new("\083\101\097\116")R.Size=Vector3.new(4,1,2)elseif G=="\086\101\104\105\099\108\101 \083\101\097\116"then R=Instance.new("\086\101\104\105\099\108\101\083\101\097\116")R.Size=Vector3.new(4,1,2)elseif G=="\083\112\097\119\110"then R=Instance.new("\083\112\097\119\110\076\111\099\097\116\105\111\110")R.Size=Vector3.new(4,1,2)end R.TopSurface=Enum.SurfaceType.Smooth R.BottomSurface=Enum.SurfaceType.Smooth R.Anchored=true return R end
-- Types of joints to assume should be preserved
local ManualJointTypes = Support.FlipTable({ "Weld", "ManualWeld", "ManualGlue", "Motor", "Motor6D" })

function SearchJoints(Haystack, Part, Whitelist)
	-- Searches for and returns manual joints in `Haystack` involving `Part` and other parts in `Whitelist`

	local Joints = {}

	-- Search the haystack for joints involving `Part`
	for _, Item in pairs(GetChildren(Haystack)) do
		-- Check if this item is a manual, intentional joint
		if ManualJointTypes[Item.ClassName] and (Whitelist[Item.Part0] and Whitelist[Item.Part1]) then
			-- Save joint and state if intentional
			Joints[Item] = Item.Parent
		end
	end

	-- Return the found joints
	return Joints
end

function RestoreJoints(Joints)
	-- Restores the joints from the given `Joints` data

	-- Restore each joint
	for Joint, JointParent in pairs(Joints) do
		Joint.Parent = JointParent
	end
end

function PreserveJoints(Part, Whitelist)
	-- Preserves and returns intentional joints of `Part` connecting parts in `Whitelist`

	-- Get the part's joints
	local Joints = GetPartJoints(Part, Whitelist)

	-- Save the joints from being broken
	for Joint in pairs(Joints) do
		Joint.Parent = nil
	end

	-- Return the joints
	return Joints
end

function CreatePart(PartType)
	-- Creates and returns new part based on `PartType` with sensible defaults

	local NewPart

	if PartType == "Normal" then
		NewPart = Instance.new("Part")
		NewPart.Size = Vector3.new(4, 1, 2)
	elseif PartType == "Truss" then
		NewPart = Instance.new("TrussPart")
	elseif PartType == "Wedge" then
		NewPart = Instance.new("WedgePart")
		NewPart.Size = Vector3.new(4, 1, 2)
	elseif PartType == "Corner" then
		NewPart = Instance.new("CornerWedgePart")
	elseif PartType == "Cylinder" then
		NewPart = Instance.new("Part")
		NewPart.Shape = "Cylinder"
		NewPart.Size = Vector3.new(2, 2, 2)
	elseif PartType == "Ball" then
		NewPart = Instance.new("Part")
		NewPart.Shape = "Ball"
	elseif PartType == "Seat" then
		NewPart = Instance.new("Seat")
		NewPart.Size = Vector3.new(4, 1, 2)
	elseif PartType == "Vehicle Seat" then
		NewPart = Instance.new("VehicleSeat")
		NewPart.Size = Vector3.new(4, 1, 2)
	elseif PartType == "Spawn" then
		NewPart = Instance.new("SpawnLocation")
		NewPart.Size = Vector3.new(4, 1, 2)
	end

	-- Make part surfaces smooth
	NewPart.TopSurface = Enum.SurfaceType.Smooth
	NewPart.BottomSurface = Enum.SurfaceType.Smooth

	-- Make sure the part is anchored
	NewPart.Anchored = true

	return NewPart
end
