The “JoinToOutsiders” function needs a table of objects such as {workspace.A,workspace.B} in the first argument, not a single object.
possible fix (haven’t tested it yet) :
local parts = {} -- empty table
for _,p in ipairs(M:GetDescendants()) do
if p:IsA("BasePart") then
table.insert(parts,p) -- add the part to the table
end
end
workspace:JoinToOutsiders(parts,Enum.JointCreationMode.All) -- Use the table of objects for the first argument