Problem unlinking constraints within a model

What I had hoped to achieve was a script that, when a certain condition (that I have not created yet) is met, it dismantles the entire model. I had noticed within the model’s children itself, that there were different constraints when I had first only sought to remove only the welds within the children of the model’s model(The model has a model that contains the physical objects). I adjusted the script accordingly but did not get any results, as the car remains in one piece regardless if the script successfully runs.

NOTE THIS: The hierarchy of objects within the script is as follows
Tormenator–> Car–> Everything else.

CODE

local seat = Tormenator.VehicleSeat
local chatterbox = Tormenator.chatterBox
local destroyed = game.ReplicatedStorage.Upon_Being_Broken
local bool = false 
local parts = Tormenator:GetChildren()

if true then 
local function dismantle(obj)
    local welds = obj:GetChildren()
    for _, weld in pairs(welds) do
        if weld:IsA("Weld") or weld:IsA("WeldConstraint") or weld:IsA("Snap") or weld:IsA("Rotate") then
             weld:Destroy()
      end
   end
end

if Tormenator and Tormenator:IsA("Model") then 
    dismantle(Tormenator) 
        print("Yay") 
        for i = 1, #parts do 
          if parts:IsA("Weld") then
            parts[i]:Destroy() 
       end
    end
else 
    print("Nay")
   end 
end```

This might seem like a silly question, but are you checking the model during testing, like physically going through the model and seeing that the welds have been destroyed? Also, are your model pieces unanchored?

One little thing I forgot to paste in, the line referencing the model itself:
local Tormenator = workspace.Tormenator.Car

Yes, I have checked the model itself. It still had the welds, rotates and snaps respectively, contained in each part that had one of the 3 before, all of the parts are unanchored.

I assume the print statements are all printing too?

You’d have made a correct assumption then. Yes, they are printing as they should.

I would try removing the “If true” part of this first function, i dont think its getting past that part when the function is called.

I tried it, unfortunately, it did not work.

You can use Model:BreakJoints() or BasePart:BreakJoints().

Didn’t work, also I believe that function is deprecated.

It is? I had no idea it was deprecated! Also, if it didn’t work, the issue might not be constraints. Maybe you can check for a constraint wrapper, since BasePart exists.

I fixed it, and for anyone who is having the same problem, here’s the solution:

--get the model.
local model = script.Parent 
--you can do 'i,' or '_,' for the 'for' loop, both do the same thing.
for _, parts in pairs(model:GetDescendants()) 
      if parts:IsA("BasePart") then
         parts:BreakJoints() 
   end
end

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