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