My script doesn't work as intended

so yea I’m working on a Lag Testing game where if you click a certain button it will generate parts in the middle of the world with 0 mile secs.

so basically I made a reset button and named all the generated parts as “lag”
and I made it so if you click that reset button it’ll remove every part, in workspace that named as “lag” basically the generated parts, and if you click the “reset” button that I made, it removes every part that named “lag” each time you click on the “reset” button instead of removing all at once.

here’s the script, inside of the RESET GUI Button.

local ScreenGui = script.Parent
local TextButton = ScreenGui.TextButton


If you don’t understand what i mean by that, I uploaded this video here is the link for it:

When you do workspace.lag it only accesses one object named “lag”, which one it picks is random.

What you’d want to do instead is check all the children of Workspace and call Destroy on each one named “lag”.

Alternatively, put all the lag parts into another object (like a Folder or Model), then call ClearAllChildren on the containing object.

1 Like

Its because you are only referencing one part. You need to loop of put them in a folder and use :ClearAllChildren

1 Like
for i,v in ipairs(workspace:GetChildren()) do 
if v.Name == "lag" then

How do i script the part so it will be spawned within the folder?

Update: nevermind I solved it, thanks for getting involved and for the support!