Make welded buildings fall

1. What do you want to achieve? Keep it simple and clear!

I want to make a part fall if it is not near another part supporting it
(The whole building is welded to a ‘base’ part and to make a part fall i use BreakJoints)

2. What is the issue? Include screenshots / videos if possible!

The part does not fall, because i think the other parts hold it up

Video showing the problem

3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I used qPerfectionWeld to weld the whole house to a ‘base’ part and unanchored the base and made it unbreakable so the whole thing can fall and it can be destroyed using BreakJoints, i dont know if there is a better option to building it or if im doing something wrong

edit: i did try using IsGrounded but i didnt get it to work, i also did think of trying to make a hitbox but if there are like 2 parts floating near each other it would not work, i also did post a forum about this before and i thought it was fixed, but after some testing there was some issues

5 Likes

Turn on the weld visualization and make sure each part is connected to parts that are touching each other.

Or you can use this script that I made for my own destruction system kinda thing. You can also select the model and press weld constraint in the toolbar to do something similar.

Documentation:

Custom script:

local model = script.Parent

local descendants = model:GetDescendants()

local totalWelds = {}
for _, v : Part in pairs(descendants) do
    if v:IsA("BasePart") then
        local originalSize = v.Size
        v.Size *= 1.05 --Some parts are close but not "Directly touching, increase it for a bit"

        local touchingParts = workspace:GetPartsInPart(v)
        v.Size = originalSize
        
        for _, connectedPart in pairs(touchingParts) do
            local weld = Instance.new("WeldConstraint")
            weld.Part0 = connectedPart
            weld.Part1 = v
            weld.Parent = connectedPart
            table.insert(totalWelds,weld )
        end
    end
end
3 Likes

ohhh i see, ill try to make a similar script then, that will create a hitbox and from that hitbox weld nearby parts

ok so, im having some issues because im getting a timeout
“Script timeout: exhausted allowed execution time - WeldNearby:20”

when it goes thru this part of the code:

for _, connectedPart in pairs(touchingParts) do
			
			local weld = Instance.new("WeldConstraint")
			weld.Part0 = connectedPart
			weld.Part1 = v
			weld.Parent = connectedPart
			table.insert(totalWelds,weld )
			v.Anchored = false --Changed this, so it has gravity
		end

i added the “v.Anchored = false” and i dont know if it is that single line that affects everything

edit: i did try to add a “wait()” but then it just takes too long to weld it all

1 Like

What is the full script?

If you suspect this is the problem have you tried deleting this line and seeing if anything changes?

2 Likes

Yes, i did try but i think there are just too many parts here ill show the full thing:

local model = script.Parent

local descendants = model:GetDescendants()

print(table.maxn(model:GetChildren()))

local totalWelds = {}
for _, v : Part in pairs(descendants) do
	wait()
	if v:IsA("BasePart") then
		local originalSize = v.Size
		v.Size *= 1.02 --Some parts are close but not "Directly touching, increase it for a bit"

		local touchingParts = workspace:GetPartsInPart(v)
		for i,v in pairs(touchingParts) do
			if v.Name == "Baseplate" then
				touchingParts[i] = nil
			end
		end
		v.Size = originalSize
		--print(v)
		for _, connectedPart in pairs(touchingParts) do
			
			local weld = Instance.new("WeldConstraint")
			weld.Part0 = connectedPart
			weld.Part1 = v
			weld.Parent = connectedPart
			table.insert(totalWelds,weld )
			v.Anchored = false
			print(table.maxn(totalWelds))
		end
	end
end
1 Like

i think i would try to make it so only some parts weld, if a part alredy is welded it doesnt weld to that part

Your hunch should be correct I tried it with 3 parts and it should be ok.

Instead of using a script to weld it you can use the studio command bar to weld it so it is setup before the game runs.

You can also use do this to avoid welding to baseplate instead of looping through all the touching parts you can just skip it using the continue keyword.

local model = script.Parent

local descendants = model:GetDescendants()

print(table.maxn(model:GetChildren()))

local totalWelds = {}
for _, v : Part in pairs(descendants) do
	--wait()
	if v:IsA("BasePart") then
		local originalSize = v.Size
		v.Size *= 1.02 --Some parts are close but not "Directly touching, increase it for a bit"

		local touchingParts = workspace:GetPartsInPart(v)
		v.Size = originalSize
		--print(v)
		for _, connectedPart in pairs(touchingParts) do
			if connectedPart.Name == "Baseplate" then
				--skip welding to baseplate
				continue
			end
			local weld = Instance.new("WeldConstraint")
			weld.Part0 = connectedPart
			weld.Part1 = v
			weld.Parent = connectedPart
			table.insert(totalWelds,weld )
			v.Anchored = false
			print(table.maxn(totalWelds))
		end
	end
end
1 Like

The thing is, im trying to make a disaster survival game while you are in a hotel, and the hotel is going to make many, many parts so i dont know a fast way to weld everything like this in the studio

Im using this as test:

So the script helps alot

After waiting for a while and testing, it seems that it does work, so ill try to make the script run faster or make less welds, but it helped me take a different perspective at it, so thanks! Ill try it from here

1 Like

OK so, what i did manage to do was use the script in the game, copy the building when it was done and paste it in the game, so i will leave the final script here for anyone who needs it later

--Script by dthecoolest
local model = script.Parent

local descendants = model:GetDescendants()

print(table.maxn(model:GetChildren()))

local totalWelds = {}
for _, v : Part in pairs(descendants) do
	wait()
	if v:IsA("BasePart") then
		local originalSize = v.Size
		v.Size *= 1.02 --Some parts are close but not "Directly touching, increase it for a bit"

		local touchingParts = workspace:GetPartsInPart(v)
		v.Size = originalSize
		--print(v)
		for _, connectedPart in pairs(touchingParts) do
			if connectedPart.Name == "Baseplate" then
				--skip welding to baseplate
				print(v)
				continue
			end
				local weld = Instance.new("WeldConstraint")
				weld.Part0 = connectedPart
				weld.Part1 = v
				weld.Parent = connectedPart
				table.insert(totalWelds,weld )
				v.Anchored = false
				print(table.maxn(totalWelds))

		end
	end
end
1 Like

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