Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Clearing objects with a string?

Asked by 5 years ago

Alright, I made a mistake and placed the wrong objects in the workspace from my models, I soon realised after placing many of the blocks, I thought I could try and use a string to make it dissapear, note: I have three objects inside of it Humanoid, SelectionBox & Pointlight

first off I tried

game.Workspace:FindFirstChild("Humanoid","SelectionBox","Pointlight"):Remove() 

then

game.Workspace:FindFirstChild("Humanoid","SelectionBox","Pointlight"):Destroy() 

and after that I changed FindFirstChild to FindFirstChildOfClass and it still never worked, If anyone could tell me why & what the correct usage is that would be a great help!

1
Because FindFirstChild only takes two arguments. First is the name of the object, second is if the function needs to look recursively through all children you execute the function on. M39a9am3R 3210 — 5y
0
Can you explain that in a better way? I don't understand the 2nd argument JamiethegreatQ777 16 — 5y
0
Oh wait so I could do game.workspace:FindFirstChild("Humanoid",workspace):Delete ??? JamiethegreatQ777 16 — 5y
1
The 2nd argument is a boolean to make it check through the descendants too. That's what recursion means, as mega said. RubenKan 3615 — 5y
0
No such method as :Delete() Ziffixture 6913 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Use a loop instead:

local children = game.Workspace:GetDescendants()
for _,p in pairs(children) do
    if p.Name == "Humanoid" or "SelectionBox" or "Pointlight" then
        p:Destroy()
    end
end

Like the commentators said, FindFirstChild() takes a string and boolean parameter, not three string parameters.

Ad

Answer this question