Removing Children

What would be the best way to remove every WeldConstraint from a script inside of ServerScriptService without manually typing in: game.Workspace.Gate.Model.Model.Part1.WeldConstraint:Destroy()

Screenshot (27)

Essentially, looping through all the children of the Model, and checking if they have a WeldConstraint and if so deleting it.

This is the current script inside of ServerScriptService:

local gateModel = game.Workspace.Gate.Model
local rockModelPrimaryPart = gateModel.PrimaryPart

function destroyWelds()
-- destroy welds here
end

wait (5)
destroyWelds()

use for i,v in iparis() loop.

local gateModel = game.Workspace.Gate.Model
local rockModelPrimaryPart = gateModel.PrimaryPart

function destroyWelds()
-- destroy welds here
for _,v in ipairs(gateModel:GetDescendants()) do
if v:IsA("WeldConstraint") then
v:Destroy()
end
end
end

wait (5)
destroyWelds()

here i wrote it.

How would I use that to cycle through the children

You could do:

function destroyWelds()
 for i,v in ipairs(gateModel:GetDescendants()) do
  if v:IsA("WeldConstraint") then
    v:Destroy()  
  end
 end
end
1 Like

They both work! Thanks for the help.

2 Likes

you dont need the ipairs, Roblox even recomends not using it

Can just do

for _,v in table do

end

in this case replace table with gateModel:GetDescendants()

why would he use table if he is getting the Descendants?

GetDescendants returns a table

I do not see anywhere if Roblox does not recommend the ipairs().

It was just the old way to go through a table, it just isnt needed now

Then it still does work, Isn’t it?

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