Help converting MeshParts into SpecialMeshes

Hello, i’ve made a script that converts MeshPart's into Part's with SpecialMeshes for one of my games but i still cant get it to work properly

for _, meshpart in pairs(model:GetDescendants()) do
    if meshpart:IsA("MeshPart") then
        local newpart=Instance.new("Part", meshpart.Parent)
        newpart.CFrame=meshpart.CFrame
        newpart.Color=meshpart.Color
        newpart.CastShadow=meshpart.CastShadow
        newpart.Transparency=meshpart.Transparency
        newpart.Size=meshpart.Size
        newpart.Material=meshpart.Material
        newpart.Name=meshpart.Name
        newpart.Anchored=meshpart.Anchored
        newpart.CanCollide=meshpart.CanCollide
        local newmesh=Instance.new("SpecialMesh",newpart)
		newmesh.MeshType=Enum.MeshType.FileMesh
        newmesh.MeshId=meshpart.MeshId
        newmesh.TextureId=meshpart.TextureID
        local mult
        if meshpart.MeshSize.X>=meshpart.MeshSize.Y and meshpart.MeshSize.X>=meshpart.MeshSize.Z then
            mult=meshpart.MeshSize.X
        elseif meshpart.MeshSize.Y>=meshpart.MeshSize.X and meshpart.MeshSize.Y>=meshpart.MeshSize.Z then
            mult=meshpart.MeshSize.Y
        elseif meshpart.MeshSize.Z>=meshpart.MeshSize.X and meshpart.MeshSize.Z>=meshpart.MeshSize.Y then
            mult=meshpart.MeshSize.Z
        end
        newmesh.Scale = (newpart.Size / meshpart.MeshSize.Magnitude) / meshpart.MeshSize * mult
        meshpart:Destroy()
    end
end

The script works but it can have slight miscalculations, which makes things with many meshes look very weird

I have no idea of what i should do to fix it

1 Like

What is the purpose of the 3 if statements?

If you dont multiply “(newpart.Size / meshpart.MeshSize.Magnitude) / meshpart.MeshSize” by the biggest axis it will make the part be wayy smaller than usual-

Shouldn’t this need to be done for all 3 axes though?

what do you mean by that, the check is done for all the 3 axes

Yeah but only one is checked and thus only one has an effect on the result. It doesn’t seen right. It should only be correct when the scale factor is the same on all axes.

I still dont understand what you mean by this

Hello? can you please answer, i really want to get this thing to work