Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Clearing objects with a string?

Asked by 2 months 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 3111 — 2mo
0
Can you explain that in a better way? I don't understand the 2nd argument JamiethegreatQ777 12 — 2mo
0
Oh wait so I could do game.workspace:FindFirstChild("Humanoid",workspace):Delete ??? JamiethegreatQ777 12 — 2mo
1
The 2nd argument is a boolean to make it check through the descendants too. That's what recursion means, as mega said. RubenKan 3434 — 2mo
0
No such method as :Delete() Feahren 1576 — 2mo

1 answer

Log in to vote
0
Answered by 2 months 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