Script to weld to surrounding parts?

So i have a doomspire type game but the problem is all the parts in the tower are welded to another part in the tower using WeldConstraints. This means that when you shoot the rocket launcher it sometimes leaves floating parts.

I was wondering if there’s a way to have the parts welded to only the parts around it to prevent this or something.

Thanks

Just Weld each Part that sits on top of another Part to the one directly below it.
This should allow the rocket launcher to blow them up in a more realistic way.

1 Like

How can i do this with a script? Doing it manually would take way too long.

you can get parts near by using
workspace:GetPartBoundsInBox()
and weld them all by they offset to each other.

1 Like

Build a small section of the tower with all the welds you need in it, but don’t join the bottom row to anything yet.
Copy/Paste or Ctrl D to duplicate that section of tower and place it on top of the first section.
Weld the bottom bricks of each section to the top bricks of the previous section.
Not ‘automatic’, but it should save you a lot of time.

final script:

local tower = game.Workspace.Map.BLUE

-- removing old welds
for _, wc in pairs(tower:GetDescendants()) do
	if wc:IsA("WeldConstraint") then
		wc:Destroy()
	end
end

local welds = 0

-- creating new welds
for _, v in pairs(tower:GetDescendants()) do
	if v:IsA("BasePart") then
		local touching = workspace:GetPartBoundsInBox(CFrame.new(v.Position),v.Size)
		for part in touching do
			local weld = Instance.new("WeldConstraint",v)
			weld.Part0 = v
			weld.Part1 = touching[part]
			welds+=1
		end
	end
end
print("created "..welds.." welds")

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