Why this gives me error "Unable to cast value to Objects"?

Hi,
I am trying to join parts with this code

for _,p in ipairs(M:GetDescendants()) do
	if p:IsA("BasePart") then
		workspace:JoinToOutsiders(p,Enum.JointCreationMode.All)
	end
end

when M is model, but it gives me “Unable to cast value to Objects” error. How can i solve it?

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
1 Like

Problem is, that it doesnt join parts in the table, so I replaced p by {p}.