Okay, so I’ve got another issue. For some reason only one partical emmiter enables, here is my updated script:
local Deb = false
script.Parent.ClickDetector.MouseClick:Connect(function()
if Deb == false then
Deb = true
for _, Confetti in pairs(script.Parent.Parent.Lid.Emitter:GetChildren()) do
Confetti.Enabled = true
wait(3)
Confetti.Enabled = false
wait(3)
Deb = false
end
end
end)
Since you’re yielding inside of for loop with a wait(), it’s doing one confetti, then waits for 3 seconds, then does another one. Simply wrap the inside of the for loop with a spawn(), but preferably us coroutines. These two features make things happen in a different thread (not the truth, but ignore the details). It’s kind of like running them on a separate script. That way everything is happening in parallel at the same time. Each confetti is handled seperately at the same time as the others. info
for _, Confetti in pairs(script.Parent.Parent.Lid.Emitter:GetChildren()) do
coroutine.wrap(function()
Confetti.Enabled = true
wait(3)
Confetti.Enabled = false
wait(3)
Deb = false
end)()
end
(I do suggest what the others did, it’s more efficient)
Better way, you can do a for loop for enabling all of them, and wait 3 seconds and disable all of them again. Spawning a thread for each one isn’t efficent.
This is caused due to you having wait() inside your loop. Instead, have the script loop through the parts before it waits.
Also, you don’t really need to use coroutines. Creating a new thread for each emitters is unnecessary and expensive.
local function toggleConfettis(emitters)
for _, v in pairs(emitters) do
v.Enabled = true
end
wait(3)
for _, v in pairs(emitters) do
v.Enabled = false
end
end)
-- do your stuff here
toggleConfettis(script.Parent.Parent.Lid.Emitter:GetChildren())
script.Parent.ClickDetector.MouseClick:Connect(function()
if Deb == false then
Deb = true
for _, Confetti in pairs(script.Parent.Parent.Lid.Emitter:GetChildren()) do
Confetti.Enabled = true
wait(3)
Confetti.Enabled = false
wait(3)
Deb = false
end
end
end)
Lets talk about the debounce. You’re setting it to true but on the first loop/iteration you’re setting it to fase again. Which means it’ll only set one confetti’s property enabled to true. And back.
Aside from this. You’re also making it wait(3) each loop. Which means it’ll do something along the lines of this:
First Emitter: Enabled. Wait… Disabled. Wait…
Second Emitter: Enabled. Wait… Disabled. Wait…
It isn’t on separate coroutines/threads which means it is going to wait 6 before doing another emitter. In total it would be 6 * The amount of emitters. Try use coroutine.wrap to make them all work in some type of junction
local Debounce= false
script.Parent.ClickDetector.MouseClick:Connect(function()
if not Debounce then
Debounce = true
local Emitters = script.Parent.Parent.Lid.Emitter:GetChildren()
for Index = 1, #Emitters do
local Emitter = Emitters[Index]
coroutine.wrap(function()
Emitter.Enabled = true
wait(3)
Emitter.Enabled = false
wait(3)
end)()
end
Debounce = false
end
end)