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

How to destroy objects within a folder if it contains an instance?

Asked by 2 years ago

I have been trying to destroy objects within a folder if it contained a part named "Fake".

Basically there's a folder than has 10 different parts. some parts have a part within them named "fake", how would I destroy the parts that contain the fake part inside them

script.Parent.MouseButton1Click:Connect(function()

    local fakepart = game.Workspace["Bridging the Gap"].Map["1"].Piece.Handle:FindFirstChild("Fake")


    if  game.Workspace["Bridging the Gap"].Map["1"].Piece.Handle:FindFirstChild("Fake") then 
        game.Workspace["Bridging the Gap"].Map["1"].Piece:Destroy()

    end

end)

1 answer

Log in to vote
0
Answered by
SirGamezy 186
2 years ago
Edited 2 years ago

Use a for loop to go through each instance within the folder.

script.Parent.MouseButton1Click:Connect(function()
    for _, piece in pairs(game.Workspace["Bridging the Gap"].Map["1"]:GetChildren()) do
        if piece.Handle:FindFirstChild("Fake") then
            piece:Destroy()
        end
    end
end)

More on for loops here https://developer.roblox.com/en-us/articles/Loops https://www.youtube.com/watch?v=1ZAoVu9chN4

Ad

Answer this question