The script waits 15 seconds every time, but it doesnt have to do that

Hello :wave:

I tried this script where the script changes multiple parts in a folder, but if I run this script, it waits 15 seconds for every part to appear.

so if I run it this would happen:
1 part appears → 15 seconds later → 2nd part will appears → 15 seconds later → …

my apology if this title wasn’t that good and I misleaded you :pensive:

Can someone tell me what I’m doing wrong?

function onTouched(part)

	for index, object in next, game.Workspace.Map:GetChildren() do
		if object:IsA('Part') then
			if object.Name == 'TestPart' then
				object.Transparency = 0
				wait(15)
				object.Transparency = 1
			end
		end
	end
end

script.Parent.MouseButton1Click:connect(onTouched)

Thanks for reading this and hopefully you can help me! :smile:

task.spawn(function()
	object.Transparency = 0
	task.wait(15)
	object.Transparency = 1
end)

wait(15) yields the thread (the script’s execution) for 15 seconds, to combat this we need to create additional threads.

On an additional note, consider using “task.wait()” instead of “wait()”.