How do I enable multiple particles at once without making my script unorganized

Hello all I want is my script to make all of these blocks(1) to spit out a particle all at the same time they are all the same and all are in the same model(2) they also have the same particle emitter. But my script is only enabling and disabling one particle emitter.

local PE = game.workspace.AOE_sword_sparkles. --problem area (or at least I think it's here)

while true do
wait(5)
PE.Enabled = true
wait(0.5)
PE.Enabled = false
print("Please wait")
end
Pictures

(1)^
Capture9 (2)^

1 Like

You can loop through all of the descendants of the model, then find out if any of the descendants are particle emitters, then enable/disable them:

while true do
    wait(5)
    for i, v in pairs(AOE_sword_sparkles:GetDescendants()) do
        if v:IsA("ParticleEmitter") then
            v.Enabled = true
        end
    end
    wait(0.5)
    for i, v in pairs(AOE_sword_sparkles:GetDescendants()) do
        if v:IsA("ParticleEmitter") then
            v.Enabled = false
        end
    end
    print("Please wait")
end

Nothing is happening I got the error

Workspace.Script:3: attempt to index nil with ‘GetDescendents’

In my output

The reason is because AOE_sword_sparkles is not defined yet. To define it, make it a variable:

local AOE_sword_sparkles = game.workspace.AOE_sword_sparkles

then put that in your code:

local AOE_sword_sparkles = game.workspace.AOE_sword_sparkles

while true do
    wait(5)
    for i, v in pairs(AOE_sword_sparkles:GetDescendants()) do
        if v:IsA("ParticleEmitter") then
            v.Enabled = true
        end
    end
    wait(0.5)
    for i, v in pairs(AOE_sword_sparkles:GetDescendants()) do
        if v:IsA("ParticleEmitter") then
            v.Enabled = false
        end
    end
    print("Please wait")
end
1 Like

i would use GetChildren() instead

it works thank you!

30characters

You can use GetChildren(), but the model has more than 1 layer of children.

The code would look like this if you were to use GetChildren(), notice how much longer it is:

local AOE_sword_sparkles = game.workspace.AOE_sword_sparkles

for i, v in pairs(AOE_sword_sparkles:GetChildren()) do
    for i, w in pairs(v:GetChildren()) do
        if w:IsA("ParticleEmitter") then
            v.Enabled = true
        end
    end
end

compared to GetDescendats():

local AOE_sword_sparkles = game.workspace.AOE_sword_sparkles

for i, v in pairs(AOE_sword_sparkles:GetDescendants()) do
    if v:IsA("ParticleEmitter") then
        v.Enabled = true
    end
end