How to destroy all of something

Hi I made a placement system where players can place tape but issue I am having is when the player leaves the game it won’t destroy all the tape only 1 here is my script:

game.Players.PlayerRemoving:Connect(function(player)
if workspace:WaitForChild(player.Name.."Tape", 5) then
local Taper = workspace:WaitForChild(player.Name.."Tape", 5)
Taper:Destroy()
end
end)
2 Likes

use a for loop like:

for _,thing in ipairs(workspace:GetChildren()) do
  if thing.Name == player.name.."Tape" then
    thing:Destroy()
  end
end
5 Likes

@shadowmaster940’s solution should work.
I just wanted to add that if I were you, I would make all the tapes spawn under a “tape” folder, just for organising purposes.
This also gives the script a easier time finding all the tapes, since all it would need to do is delete the folder’s children.

2 Likes

Thanks for your help it works!! I will mark you as solution but I can’t rn error code: requested URL can’t be found keeps coming up

1 Like

That’s a good idea I might do that one day

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.