Hello fellow developers, can anyone tell me how I would use a script to delete unanchored parts in workspace?
1 Like
for i,v in pairs (workspace:GetChildren()) do
if v:IsA("BasePart") then
if v.Anchored == false then
v:Destroy()
end
end
end
3 Likes
First of all, this isn’t a site for requesting scripts. This is for pointing out the errors in your scripts.
But anyways here is the answer
for I,v in pairs(game.Workspace:GetChildren())do
if v:IsA("BasePart") and v.Anchored == false then
v:Destroy()
print("Unanchored Part was deleted")
end
end
2 Likes
Here is the script. But as @Codez_X said “this isn’t a site for requesting scripts. This is for pointing out the errors in your scripts.”
for i, part in pairs(game:GetSevice("Workspace"):GetDescendants()) do -- You can use :GetChildren if you want. :GetDescendants() is to make sure that all of the part that is in workspace and not anchored is deleted.
if part:IsA("BasePart") and part.Anchored == false then
part:Destroy()
print("Unanchored Part is deleted")
end
end
There you have it.
2 Likes
Thanks to all who replied and for the help! Greatly appreciated
I’m not too sure, as I’m a very new scripter, but I would guess roughly this would be in the script:
if Part IsA (“BasePart”) and Anchored == false then
Destroy()