07:05:08.741  The current thread cannot access 'StreamingService' (lacking capability Assistant)  -  Edit - Script:116
  07:05:08.741  Stack Begin  -  Studio
-- ConvertMeshesPlugin.lua

local plugin = plugin

-- Create a toolbar button for the plugin
local toolbar = plugin:CreateToolbar("Mesh Converter")
local button = toolbar:CreateButton("Convert Meshes", "Convert MeshParts and UnionOperations to Parts with SpecialMeshes", "rbxassetid://4458901886")

-- Function to convert MeshParts to Parts with SpecialMesh
local function convertMeshPart(meshPart)
	local part = Instance.new("Part")
	part.Name = meshPart.Name
	part.Size = meshPart.Size
	part.CFrame = meshPart.CFrame
	part.Anchored = meshPart.Anchored
	part.CanCollide = meshPart.CanCollide
	part.CastShadow = meshPart.CastShadow
	part.Locked = meshPart.Locked
	part.Material = meshPart.Material
	part.Color = meshPart.Color
	part.Transparency = meshPart.Transparency
	part.Reflectance = meshPart.Reflectance
	part.TopSurface = meshPart.TopSurface
	part.BottomSurface = meshPart.BottomSurface

	-- Create SpecialMesh
	local specialMesh = Instance.new("SpecialMesh")
	specialMesh.MeshType = Enum.MeshType.FileMesh
	specialMesh.MeshId = meshPart.MeshId
	specialMesh.TextureId = meshPart.TextureID
	specialMesh.Scale = Vector3.new(1, 1, 1)  -- Keep Scale at (1,1,1)
	specialMesh.Parent = part

	-- Parent the new part
	part.Parent = meshPart.Parent

	-- Move over any children (e.g., SurfaceAppearance)
	for _, child in ipairs(meshPart:GetChildren()) do
		child.Parent = part
	end

	-- Remove the original MeshPart
	meshPart:Destroy()
end

-- Function to convert UnionOperations to Parts with SpecialMesh
local function convertUnionOperation(unionOp)
	-- Export the UnionOperation as .obj
	local tempFolder = Instance.new("Folder")
	tempFolder.Name = "TempUnionExport"
	tempFolder.Parent = workspace
	unionOp.Parent = tempFolder

	local saveSelection = game.Selection:Get()
	game.Selection:Set({unionOp})

	local exportSuccess, exportMessage = pcall(function()
		plugin:PromptSaveSelection("UnionExport.obj")
	end)

	unionOp.Parent = tempFolder.Parent
	tempFolder:Destroy()

	if not exportSuccess then
		warn("Failed to export UnionOperation:", exportMessage)
		return
	end

	-- Import the .obj file back as a MeshPart
	-- Note: In practice, we'd need to load the file from disk, but we can't automate this step in a plugin.
	-- We'll prompt the user to manually import the .obj file as a MeshPart.

	warn("Please import the exported 'UnionExport.obj' file back into the game as a MeshPart.")

	-- Wait until the user has imported the MeshPart
	local importedMeshPart
	repeat
		wait(1)
		-- Look for a MeshPart named "UnionExport" in the workspace
		importedMeshPart = workspace:FindFirstChild("UnionExport")
	until importedMeshPart and importedMeshPart:IsA("MeshPart")

	-- Rename and re-parent the imported MeshPart
	importedMeshPart.Name = unionOp.Name
	importedMeshPart.Parent = unionOp.Parent
	importedMeshPart.CFrame = unionOp.CFrame
	importedMeshPart.Anchored = unionOp.Anchored
	importedMeshPart.CanCollide = unionOp.CanCollide
	importedMeshPart.CastShadow = unionOp.CastShadow
	importedMeshPart.Locked = unionOp.Locked
	importedMeshPart.Material = unionOp.Material
	importedMeshPart.Color = unionOp.Color
	importedMeshPart.Transparency = unionOp.Transparency
	importedMeshPart.Reflectance = unionOp.Reflectance

	-- Move over any children (e.g., SurfaceAppearance)
	for _, child in ipairs(unionOp:GetChildren()) do
		child.Parent = importedMeshPart
	end

	-- Remove the original UnionOperation
	unionOp:Destroy()

	-- Convert the MeshPart to Part with SpecialMesh
	convertMeshPart(importedMeshPart)
end

-- Function to convert all MeshParts and UnionOperations in the game
local function convertAllMeshes()
	local meshParts = {}
	local unionOperations = {}

	-- Collect all MeshParts and UnionOperations
	local function collectMeshes(parent)
		for _, child in ipairs(parent:GetChildren()) do
			if child:IsA("MeshPart") then
				table.insert(meshParts, child)
			elseif child:IsA("UnionOperation") then
				table.insert(unionOperations, child)
			end
			collectMeshes(child)
		end
	end

	collectMeshes(game)

	-- Convert MeshParts
	for _, meshPart in ipairs(meshParts) do
		convertMeshPart(meshPart)
	end

	-- Convert UnionOperations
	for _, unionOp in ipairs(unionOperations) do
		convertUnionOperation(unionOp)
	end

	print("Conversion complete.")
end

-- Connect the button click to the conversion function
button.Click:Connect(function()
	convertAllMeshes()
end)