How do I delete Parts in Workspace with the same name without grouping them into a Model?

I am trying to find a way to locally destroy parts called “Waypoint” without grouping them into a Model. My aim is to delete the “Waypoint” blocks locally on players that have role id less than 10 (not a staff member) and do nothing if the player has role id greater than or equal to 10 (a staff member role).

Here is the LocalScript added in StarterPlayerScripts where I have to locally delete “Waypoint” parts if user is not a staff member (role id less than 10).

local player=game.Players.LocalPlayer 
local rank = player:GetRankInGroup(12646662) 
if rank >= 10 then
	warn("User is staff, waypoint is shown.")
elseif rank < 10 then
	-- Delete all of "Waypoint" bricks in Workspace.
	end
end

Question is, how do I delete all of the parts called “Waypoint” in Workspace without putting them inside a grouped Model/Folder? Thank you.

This should work:

local player=game.Players.LocalPlayer 
local rank = player:GetRankInGroup(12646662) 
if rank >= 10 then
	warn("User is staff, waypoint is shown.")
elseif rank < 10 then
   for _, v in pairs(game.Workspace:GetDescendants()) do
       if v:IsA("BasePart") and v.Name == "Waypoint" then 
          v:Remove()
       end
   end
end
2 Likes

I don’t see why you can’t use a model (or folder). The more parts and objects you have the more performance heavy/longer it can take to loop through all game.Workspace:GetDescendants()
A folder doesn’t change the selection behaviour on parts like models do, but for models you can hold shift down to select individual parts. I would really recommend to use a model or folder to have the code loop through much less objects.