Need help with enabling multiple particles

I’m having an issue with enabling multiple particles in one script line, and I’m not sure how to do so.


In this script, I can only put one particle (to my knowledge).
Screen Shot 2022-12-28 at 7.32.34 PM
This image shows that there are still 3 other particles I want to have enabled.

Is there any way to do this?

Try using a for loop

local particles = workspace.Lighting.cannon.particleCore

-- Within Input:

for number,index in pairs(particles:GetChildren()) do
   if index:IsA("ParticleEmitter") then
      index.Enabled = false
   end
end

You can change false to not i.Enabled if you like :slight_smile:

1 Like

Is the orange line under “i” of any concern?

woops,

Change i to index

Doesn’t seem to work.

Is this the right setup?

No,

For a Better idea try this:

local particles = workspace.Lighting.cannon.particleCore


function Example()
   for number,index in pairs(particles:GetChildren()) do
      if index:IsA("ParticleEmitter") then
         index.Enabled = not index.Enabled
      end
   end
end


userInputService.InputBegan:Connect(function(input, gp)
   if gp then return end

   if input.KeyCode = Enum.KeyCode.C then
      Example()
   end

end)

userInputService.InputEnded:Connect(function(input, gp)
   if gp then return end

   if input.KeyCode = Enum.KeyCode.C then
      Example()
   end

end)

Minor spelling mistake on “Lighting” but I fixed it.

Thanks! :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.