Hello. I need a script that gets rid of the workspace in my game. Something that gets the children of a workspace, and then deletes all the children when the game is launched. Any scripts?
To iterate over all children of Workspace, destroying each, we'll use:
ipairs
functionworkspace
global variableInstance:GetChildren
methodInstance:Destroy
methodInstance:IsA
method.for _, child in ipairs(workspace:GetChildren()) do if not child:IsA("Terrain") then child:Destroy() end end
Note our use of Instance:IsA
to check if the child is a Terrain
, which cannot be destroyed and throws an error upon an attempt.
Normally, I'd recommend to use the :ClearAllChildren() method, but that won't work properly with Workspace as the Terrain Instance may not be deleted. So instead, simply loop through the children and delete them.
for _, v in pairs(workspace:GetChildren()) do if not v:IsA("Terrain") then v:Destroy() end end
Dunno why you'd want to do this but ok..
for _, child in ipairs(workspace:GetChildren()) do if not child:IsA("Terrain") then child:Destroy() end end
Closed as Not Constructive by User#24403, BenSBk, green271, and zblox164
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?