Is there a better way to do this?

is there any better way to do something like this like making it shorter maybe just because i dont want to have to right out 100s of these

game.workspace.a.particleemitter.enabled = true
game.workspace.b.particleemitter.enabled = true
game.workspace.c.particleemitter.enabled = true
game.workspace.d.particleemitter.enabled = true
game.workspace.e.particleemitter.enabled = true
game.workspace.f.particleemitter.enabled = true

1 Like

Yes. put all the parts with particle emitters and put them inside a model. Then do something along the lines of this:

for _, Descendant in ipairs (game.Workspace.Model:GetDescendants()) do 
   if (Descendant:IsA("ParticleEmitter")) then
       Descendant.Enabled = true
  end
end

EDIT: The person below me pointed out my mistake, I have fixed it.

2 Likes

@DaBisawesome123 method is partially correct but you would need to directly reference them or use GetDescendants():

for _,Child in ipairs (game.Workspace.Folder:GetChildren()) do
	Child.particleemitter.Enabled = true
end
--or 
for _, Descendant in ipairs (game.Workspace.Folder:GetDescendants()) do 
   if (Descendant:IsA("ParticleEmitter")) then
       Descendant.Enabled = true
  end
end
2 Likes

No you did not lol, you just did, and you still have to wrong method its GetDescendants() you have Descendants(),

I would recommend you use a folder instead of a model actually since it will be easier to edit the actual components. Also, you need to do this on the server since all the parts it workspace may not be available at runtime.

1 Like

it worked fine for me but i will put them in a folder

1 Like