I'm new to generic for loops, and for that matter, fairly new to scripting in general.
I made this click detector that if touched, creates 5 parts and then waits 3 seconds and destroys them. I don't need this for a game of mine, but am simply using it so that when the time comes to use generic for loops, I have experience with them.
Here is my code:
local clickdetector = script.Parent:WaitForChild("ClickDetector")
clickdetector.MouseClick:connect(function()
for i = 1,5,1 do
local part = Instance.new("Part",game.Workspace)
end
end)
for i,part in pairs(game.Workspace:GetChildren()) do
if part.Name == 'part' then
wait(3)
part:Destroy()
end
end
When I play the game no errors print in the output. I don't understand what I'm doing wrong. If you can please help me thank you, and even if you can't thank you for your time.

3 comments
You could just make the if-statement search for an uppercase "Part" instead, but I was just trying to show you why exactly this did not work.
It is game.workspace that is deprecated not game.Workspace
Edited