How do I change the property of all children at once?

So I have been making a script after watching a car health tutorial but I got a problem.

I have been modifying it a bit with the EXTREMELY LIMITED knowledge I have on scripting but when I was doing something so all ParticleEmitters are enabled.

With another post I used something called pairs and GetChildren() which made my particle emitters get enabled… but it was a like single-file line and they were waiting for each one to pass by the line, then pass themselves

It is a lot of particle emitters (14)

How do I make it so all of them instead of patiently waiting, throw themselves like crazy, breaking the single-file line and enabling themselves at the same time?

Full script (I dont know anything, please dont judge

  	for _, child in ipairs(script.Parent.Parent.Explosion:GetChildren()) do
  		if child:IsA("ParticleEmitter")then
  			child.Enabled = true
  			wait(0.6)
  			child.Enabled = false
  		end
  	end
2 Likes

Script:

for _, child in ipairs(script.Parent.Parent.Explosion:GetChildren()) do
	if child:IsA("ParticleEmitter") then
		coroutine.wrap(function()
			child.Enabled = true
			task.wait(0.6)
			child.Enabled = false
		end)()
	end
end

coroutine.wrap allows for multiple threads to run at once, therefore allowing multiple task.wait to run at once in each thread.
(also, don’t worry about being a beginner, everyone was there one day)

1 Like
for _, child in ipairs(script.Parent.Parent.Explosion:GetChildren()) do
	if child:IsA("ParticleEmitter")then
		spawn(function()
			child.Enabled = true
			wait(0.6)
			child.Enabled = false
		end)
	end
end

this works for me

1 Like

oh yeah this works too, idk which one is better

1 Like

Yea, I used coroutine.wrap because spawn is deprecated so I think coroutine.wrap is better, don’t know though.

1 Like

Excellent! Now I can explode cars and kill people faster other than smoke appearing, then debris, then 1 part of the fire, then another smoke!

1 Like

This one didnt work for some reason though, the only difference it said that it has a routine

1 Like

I actually prefer your implementation over the “spawn()” global which has now been superseded by the task library function “task.spawn()”.

The only issue is that you’re missing the pair of enclosing parentheses after the coroutine.wrap() call in order to call the function (routine) it returns.

coroutine.wrap(function()
	child.Enabled = true
	task.wait(0.6)
	child.Enabled = false
end)()

Alternatively, you could also do:

coroutine.resume(coroutine.create(function()
	child.Enabled = true
	task.wait(0.6)
	child.Enabled = false
end)

We could even simply use “task.delay()” which delays for some period of time (without yielding, as an additional thread is created) before executing some function.

for _, child in ipairs(script.Parent.Parent.Explosion:GetChildren()) do
	if child:IsA("ParticleEmitter") then
		child.Enabled = true
		task.delay(0.6, function()
			child.Enabled = false
		end)
	end
end
2 Likes