I’m working on this boulder obby and wanted to make custom boulders for my friends when they joined. I was working on adding accessories to the boulders and having them welded to the boulder as they pushed it along. I ran into a quick problem as the welds seem to break when I was cloning the boulder model into workspace. Here’s the outcome:
(the chicken hat has CanCollide on so I can see what’s going on when the boulder spawns)
I’ve already tried figuring out the issue and troubleshooting but nothing works! Not even :MakeJoints()!
You can do the always-working silly solution, however, it ignores completely the point of the post, about why the model doesn’t weld correctly:
--script inside model
local model = script.Parent
local primary = model.PrimaryPart
local welds = Instance.new("Folder", model)
welds.Name = "Welds"
for _, part: BasePart in pairs(model:GetDescendants()) do
if not part:IsA("BasePart") then continue end
if not primary then primary = part continue end
local weld = Instance.new("WeldConstraint")
weld.Part0 = primary
weld.Part1 = part
weld.Name = part.Name
weld.Parent = welds
end
I’m not entirely sure, but I think when instances are cloned the references of their parts in the weld properties are set to nil because the model parts are different/new and have a different location in memory.
PS: The above sample welds all parts to a single part, which means that if that part gets destroyed all other parts will break. Another option you have is connecting everything to everything(which, correct me if mistaken, takes n*logn operations to finish where n is the number of parts to weld), and if you plan to use said objects for physics its optimal to use smarter welding methods that force-weld parts with only the parts around them.
I tried something along the lines of this, already having a weld in the accessory and linking every part to the respective items, but they just kept falling off.
The instance WeldConstraint can also glue parts that aren’t physically touching, also the script above must run in the model after you clone it(right after to be specific, with no time delays else the parts might move a bit).