WeldConstraint deleting its Part1 upon being cloned

Hey everybody!
The title pretty much describes the whole situation: I have some code to procedurally generate some houses on a map, with each house’s position being set to a different point for each house.
I have made two house models, a single-story one and a double-story one.
When I run the code, the single story houses are cloned and placed correctly, but when I try with the other model…


…this happens.
The grass (which is also the model’s PrimaryPart) does get cloned just fine, but all the other parts seem to not be connected.

In the explorer, each part has an enabled WeldConstraint with Part0 set to itself and Part1 set to the PrimaryPart, but when I run the game and check none of the WeldConstraints have a Part1 anymore…

Any ideas? This is the replication code btw:

local function GenerateHouse(Plot:Part)
	
	local Model = HouseModels[math.random(1,#HouseModels)]
	
	local House = Model:Clone()
	
	local PrimaryColor = Palettes.WallsPrimary[math.random(1,#Palettes.WallsPrimary)]
	local SecondaryColor = Palettes.WallsSecondary[math.random(1,#Palettes.WallsSecondary)]
	local RoofColor = Palettes.Roof[math.random(1,#Palettes.Roof)]
	
	for _, part in pairs(House.WallsPrimary:GetChildren()) do
		part.Color = PrimaryColor
	end
	
	for _, part in pairs(House.WallsSecondary:GetChildren()) do
		part.Color = SecondaryColor
	end
	
	for _, part in pairs(House.Roof:GetChildren()) do
		part.Color = RoofColor
	end
	
	House.PrimaryPart.CFrame = Plot.CFrame
	House.Parent = workspace.Houses
	
end

Where “Plot” is a placeholder part that stores the position of the house.

If you need any more details please say so

I assume you mean that the Part1 property is blank (or nil).

A way to figure out the issue is to look over each property of the WeldConstraint or the primary part.

Here’s some examples of things to look for:

  • Are you sure that the Part1 of the WeldConstraints in the original explorer references the primary part of the double-story house?
    • As mentioned in Clone, the reference property of the cloned Instances will refer either to the original Instance (if it’s not cloned together) or to a cloned Instance.
    • If the Part1 doesn’t reference the primary part of the double-story house, the cloned WeldConstraints also won’t be referencing the primary part of the cloned double-story house.
  • Can you check if the primary part of the double-story house has Archivable set to true?
    As mentioned in your post, the grass does get cloned, so this doesn’t seem to be the issue.

You can also print out the Part1 properties of the WeldConstraints before and after cloning to figure out the time where the property is nil.

Also, about the replication code, here are some suggestions:

  • As mentioned here, it’s not necessary to use pairs to iterate through a table in Luau.
  • Use PivotTo to move the house model instead of setting the primary part’s CFrame.
  • Store workspace.Houses in a variable outside the function scope.
    This way, you don’t need to re-access the Houses instance parented to workspace every time you set the House.Parent.
1 Like

Thank you for making me check wether the reference was the primary part of the double-story house, I realized that the problem was that I was welding each part to the primary part of the single-story house inside ReplicatedStorage to it: that’s why it never worked.

Also, thank you so much for the other tips! I’ll make sure to implement them.

1 Like

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