Variation within the collapsing structure

Hi!

This is kinda a continuation of a separate topic I made, but also not really.

I’ve been working on a structure fall test that has been proven to be working exponentially – however, I’ve encountered a tiny nitpick when creating the code.

I’ve played in solo mode a many times when it just occurred to me that it seems the script picks the same Weld over and over in the same chronological order, every time. It does not randomly pick Weld to break, it goes by the order of its own.

I’m a little skeptical of how I can go around this problem. All the Welds are placed within the single part called Base (which keeps the entire model together). I was thinking of creating math.random picker, but all the welds are named “Weld,” so I’m not sure if it would make a difference in the world. If that could be the case, how can I go about it?

local structureDebris = workspace.StructureTest:GetChildren()

    while true do
	wait(.5)
	if workspace.StructureTest.Base:FindFirstChildOfClass("Weld") then
		workspace.StructureTest.Base:FindFirstChildOfClass("Weld"):Destroy()
	else
		for _, v in pairs(structureDebris) do
			wait(.1)
			v:Destroy()
		end
		
		break
		
	end
end

StructureTest is a group, the structure itself.
Base is the PrimaryPart of the group where all the Welds are at Parented at.

How can I go about adding variation to the structure fall and not having it fall the same way over and over again?

Disregard, I figured out the solution.

I would recommend putting all of your welds in a table. Then using math.random to remove one at random.

local Welds = {}
local StructureTestObjects = workspace.StructureTest.Base:GetChildren()
for i = 1, #StructureTestObjects do
    if StructureTestObjects[i].ClassName == "Weld" then
        table.insert(Welds, StructureTestObjects[i])
    end
end

while true do 
    wait(0.5)
    if #Welds > 0 then
        Welds[math.random(1, #Welds)]:Destroy()
    end
end
1 Like