Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to properly remove a child from a parent?

Asked by 7 years ago

Hey, I've been trying to remove a child from a parent, but for some reason this doesn't execute, yet no errors lie in the output.

while wait() do
    index = 0
    for index, child in pairs(workspace:FindFirstChild("20PercentBrickMesh"):GetChildren()) do
    if child.Name == "Mesh" then child:Destroy()
    print("Removed:" .. index .. child) 
    index = index + 1
end
end
end

My objective here was to grab all the 20PercentBrickMeshes, and delete the Meshes inside of them, as they lag up the server. The setup in the Hierarchy of the parts are:

game-> Workspace -> 20PercentBrickMesh -> Mesh

I'm not sure what's wrong.

0
You should just use i instead of index since i is automatically a local variable and will update and also instead of child.Name == "Mesh" do child:IsA("Mesh"). You're also destroying the child so print is receiving a nil value. If that doesn't work then provide Meltdown81 309 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

you could use ClearAllChildren

Ad

Answer this question