SpecialMesh to MeshPart conversion issue

1. The Goal
I am attempting to construct a simple local plugin for rigging characters, converting accessories into MeshPart, organizing them in folders and welding them. This is to aid in rigging up characters and keeping them clean and organized.

2. The Main Issue
But upon testing, the plugin results in this error:

The current thread cannot write 'MeshId' (lacking capability NotAccessible)

This error is referring to this line of code: meshPart.MeshId = meshId
I am aware this error occurs because Roblox restricts changing MeshId dynamically because it affects the collision model, which can’t be recalculated safely during runtime.

But what I’m trying to wrap my head around is how someone bypassed this issue? See, I’m primarily making this plugin to be a better version of the Special Mesh to Mesh Part plugin by @TheGrimDeathZombie, with extra features personally to help me with setting up rigs for animations. The plugin does exactly what I can’t get to work. Convert a SpecialMesh to a MeshPart

3. Attempted Solutions

  • I’ve attempted to use the InsertService:CreateMeshPartAsync() but with no luck, as I’d need to own the MeshAsset to make it work.
  • I have consulted the documentation for solutions, but no luck either.

As a result, I’m at a stopping point and can’t find how to fix this issue. Is there a solution to this?

for _, part in ipairs(accessory:GetChildren()) do
					if part:IsA("BasePart") then
						local sm = part:FindFirstChildOfClass("SpecialMesh")
						if sm then
							local meshId    = sm.MeshId
							local texId     = sm.TextureId
							local worldC0   = part.CFrame
							local worldSize = part.Size

							-- ensure a Folder named after the body part exists
							local partFolder = bodyPart:FindFirstChild(bodyPart.Name)
							if not partFolder then
								partFolder = Instance.new("Folder")
								partFolder.Name   = bodyPart.Name
								partFolder.Parent = bodyPart
							end

							-- create MeshPart instead of Part + SpecialMesh
							local meshPart = Instance.new("MeshPart")
							meshPart.Name         = part.Name
							meshPart.Size         = worldSize
							meshPart.MeshId       = meshId
							meshPart.TextureID    = texId
							meshPart.CanCollide   = false
							meshPart.Anchored     = false
							meshPart.CFrame       = worldC0
							meshPart.Transparency = part.Transparency
							meshPart.Color        = part.Color
							meshPart.Material     = part.Material
							meshPart.Parent       = partFolder

							-- ensure a Welds folder
							local weldsFolder = bodyPart:FindFirstChild("Welds")
							if not weldsFolder then
								weldsFolder = Instance.new("Folder")
								weldsFolder.Name   = "Welds"
								weldsFolder.Parent = bodyPart
							end

							-- weld the MeshPart to the body part
							local weld = Instance.new("WeldConstraint")
							weld.Name   = part.Name .. "_Weld"
							weld.Part0  = bodyPart
							weld.Part1  = meshPart
							weld.Parent = weldsFolder
						end
					end
				end

Use InsertService:CreateMeshPartAsync with MeshPart:ApplyMesh. You might have to reset a few properties after you apply the mesh, such as the texture.

local InsertService = game:GetService("InsertService")

local function ChangeMeshId(Part: MeshPart, MeshId: string): boolean
	local Success, LoadedMesh = pcall(
		InsertService.CreateMeshPartAsync, InsertService,
		MeshId, Part.CollisionFidelity, Part.RenderFidelity
	)
	
	if Success then
		Part:ApplyMesh(LoadedMesh)
		return true
	end
	
	return false
end
1 Like

Alright thanks! I modified the script and got it working perfectly! Had to go through some troubleshooting with the Scaling but i eventually got it working.

Thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.