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)
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