The code given above is incorrect due to the fact that it checks the name of each descendant and not the group, so you’d need to have multiple parts having the same name.
For groups:
You loop through workspace:GetDescendants() and check if it is a model and if yes, check its name. If it qualifies for being unanchored then you loop through that model and unanchor each part, or if its a base part you want to unanchor.
Here’s an example:
for i, desc in pairs(workspace:GetDescendants() do
if desc.Name == "UnAnchorName" then
if desc:IsA("Model") then
for _, part in pairs(desc:GetDescendants() do
if part:IsA("BasePart") then
part.Anchored = false
end
end
elseif desc:IsA("BasePart") then
desc.Anchored = false
end
end
end
for i, desc in pairs(workspace:GetDescendants()) do
if desc.Name == "UnAnchorName" then
if desc:IsA("Model") then
for _, part in pairs(desc:GetDescendants()) do
if part:IsA("BasePart") then
part.Anchored = false
end
end
elseif desc:IsA("BasePart") then
desc.Anchored = false
end
end
end