[SOLVED] How do I weld MeshParts together via a script?

I know that :Makejoints() has been depreciated, and that using :WeldConstraint is the meta now, but how do I weld MeshParts together?

I recently commissioned a modeler yo make a low poly humvee model for my game, and whenever I try to do something with it, the humvee breaks every time.

Even when using a regen button that utilized the following code,

model = script.Parent.Parent
backup = model:clone()
enabled = true
function regenerate()
	model:remove()
	wait(1)
	model = backup:clone()
	model.Parent = game.Workspace
	for i,v in pairs(model:GetDescendants()) do
		if v:IsA('MeshPart') and v.Name ~= 'MainPart' then
			local w = Instance.new('WeldConstraint')
			w.Parent = v
			w.Part0 = v
			w.Part1 = model.MainPart
		end
	end
	script.Disabled = true
	script.Parent.BrickColor = BrickColor.new(26)
	wait(2)
	script.Parent.BrickColor = BrickColor.new(104)
	script.Disabled = false
end
function onHit(hit)
	if (hit.Parent:FindFirstChild("Humanoid") ~= nil) and enabled then
		regenerate()
	end
end
script.Parent.Touched:connect(onHit)

This still occurs:
https://gyazo.com/4271d8ed9a89916e1d387a0f1e6f7c23

What’s the solution? The entire humvee model is MeshParts

When you group up all the parts of the vehicle, make sure you go into the properties of the Group instance and select which Part is the PrimaryPart.

Then instead of this:

model = backup:clone()
model.Parent = game.Workspace

for i,v in pairs(model:GetDescendants()) do
	if v:IsA('MeshPart') and v.Name ~= 'MainPart' then
		local w = Instance.new('WeldConstraint')
		w.Parent = v
		w.Part0 = v
		w.Part1 = model.MainPart
	end
end

Try this:

model = backup:clone()
model.Parent = game.Workspace

PrimaryInModel = workspace.ModelNameHere
PartsOfModel = workspace.ModelNameHere:GetDescendants()

for k = 1,#PartsOfModel do
	if PartsOfModel[k]:IsA("Part") or PartsOfModel[k]:IsA("WedgePart") or PartsOfModel[k]:IsA("MeshPart") then
	    local weld = Instance.new("WeldConstraint")
		weld.Part0 = PrimaryInModel
		weld.Part1 = PartsOfModel[k]
		weld.Parent = PrimaryInModel
	end
end

This is usually my method of how I weld everything inside a model.

1 Like