Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Clearing objects with a string?

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!

5 comments

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.

0

Can you explain that in a better way? I don't understand the 2nd argument

0

Oh wait so I could do game.workspace:FindFirstChild("Humanoid",workspace):Delete ???

1

The 2nd argument is a boolean to make it check through the descendants too. That's what recursion means, as mega said.

0

No such method as :Delete()

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.