Can I change this script to make it remove all parts named "Spikes_Simple" [[ function lock(target) pcall(function(target) target.Locked = true end, target) for _,v in pairs(target:getChildren()) do lock(v) end end lock(script.Parent) ]]
I'm not sure whether you are trying to Lock or Remove every child with a certain name, but from your title, it seems like you want them destroyed.
You could either use a simple for loop, like so..
for i,child in pairs(parent:GetChildren()) do if child:IsA('BasePart') and child.Name == 'Name' then child:Destroy -- or Child.Locked = true end end
Alternatively, you could use recursion (which I believe is what you were aiming for), to look through every descendant of a certain item, and lock every item matching a set expectation, like so..
local recurse = function (parent) for i, child in ipairs(parent:GetChildren()) do -- loops through the provided `parent`'s children if not (child:IsA('Model')) then --direct descendant is not a `Model` child:Destroy() -- or child.Locked = true else recurse( child ) -- runs the function again on `child ` end end end recurse( workspace['path to parent'] ) -- call function on model