How do I make multiple particle emitters activated at the same time?

I grabbed a random effect pack from the Toolbox. But the script only activates one Particle emitter. I’m not so good at scripting so maybe someone knows how to make multiple particle emitters activate at once.
Stage - Roblox Studio 19.02.2022 14_35_17
In side of the Model “Fire”
Stage - Roblox Studio 19.02.2022 14_38_01

script.Parent.MouseButton1Click:connect(function()
local p = game.Workspace.FX.Fire:GetChildren()

for i = 1 ,#p do

p[i].ParticleEmitter.Enabled = true
p[i].Sound:Play()
end
end)

That script seems like it should work I can’t see any problems, check all of the particle emitters are in game.Workspace.FX.Fire and all of the models are not inside each other

I’d recommend using CollectionService if you have loads of emitters

Fire is a model that includes the particle emitter and the parts for the emitter.

Stage - Roblox Studio 19.02.2022 14_35_17

Ok yeah I see the problem now
Solution:

script.Parent.MouseButton1Click:connect(function()
local p = game.Workspace.FX:GetChildren()

for i = 1 ,#p do

p[i].F1.ParticleEmitter.Enabled = true
p[i].F1.Sound:Play()
end
end)

Basically you were just getting getting 1 Fire model and getting the children inside that model. So there would only be 1 item returned

game.Workspace.FX.Fire:GetChildren()

It still activates only one for some reason

Did you use the whole of this script

script.Parent.MouseButton1Click:connect(function()
local p = game.Workspace.FX:GetChildren()

for i = 1 ,#p do

p[i].F1.ParticleEmitter.Enabled = true
p[i].F1.Sound:Play()
end
end)

And not the script I put at the bottom of my previous reply

I didn’t use the one little one on the bottom of your post. Only the bigger one that you posted again.

Then there must be an issue with the models in your game because the script should cycle through all of the emitters. Is any errors coming up in the output log?

Nope no, errors to be seen. It activates all the same particle emitter all of the time. I understand the script but the only thing that I don’t know is what does the [i] before the p means.

for i = 1 ,#p do

basically this is a “for loop” which cycles for how many models there is inside #p
So basically if the loop has gone through 2 times i = 2, and if the loop is on its 10th cycle i = 10.
Therefore if the loop is on its 7th cycle it would be like p[7]
Hope this makes sense Loops

Well that gives me no idea how to still fix this script

I just told you what i means like you asked…
And the script is fixed you did

game.Workspace.FX.Fire:GetChildren()

which means that the script only cycled through 1 fire.
Wheras the fixed cycles through the FX model and get all of the children

game.Workspace.FX:GetChildren()

Then the other section changes to this… Because p = fire, therefore p[i].F1.part… = fire.f1.part…

p[i].F1.ParticleEmitter.Enabled = true
p[i].F1.Sound:Play()

The script is fixed, you just need to implement it properly into your code.

local root = workspace.FX
local f1 = root.Fire1
local f2 = root.Fire2
local f3 = root.Fire3
local f4 = root.Fire4
local f5 = root.Fire5
local f6 = root.Fire6
local f7 = root.Fire7
local f8 = root.Fire8
local f9 = root.Fire9
local f10= root.Fire10
local f11= root.Fire11
local f12= root.Fire12
local f13= root.Fire13
local f14= root.Fire14
local f15= root.Fire15
local f16= root.Fire16
local f17= root.Fire17
local f18= root.Fire18

script.Parent.MouseButton1Click:connect(function()
	f1.F1.ParticleEmitter.Enabled = true
	f1.F1.Sound:Play()
	
	f2.F1.ParticleEmitter.Enabled = true
	f2.F1.Sound:Play()
	
	f3.F1.ParticleEmitter.Enabled = true
	f3.F1.Sound:Play()
	
	f4.F1.ParticleEmitter.Enabled = true
	f4.F1.Sound:Play()
	
	f5.F1.ParticleEmitter.Enabled = true
	f5.F1.Sound:Play()
	
	f6.F1.ParticleEmitter.Enabled = true
	f6.F1.Sound:Play()
	
	f7.F1.ParticleEmitter.Enabled = true
	f7.F1.Sound:Play()
	
	f8.F1.ParticleEmitter.Enabled = true
	f8.F1.Sound:Play()
	
	f9.F1.ParticleEmitter.Enabled = true
	f9.F1.Sound:Play()
	
	f10.F1.ParticleEmitter.Enabled = true
	f10.F1.Sound:Play()
	
	f11.F1.ParticleEmitter.Enabled = true
	f11.F1.Sound:Play()
	
	f12.F1.ParticleEmitter.Enabled = true
	f12.F1.Sound:Play()
	
	f13.F1.ParticleEmitter.Enabled = true
	f13.F1.Sound:Play()
	
	f14.F1.ParticleEmitter.Enabled = true
	f14.F1.Sound:Play()
	
	f15.F1.ParticleEmitter.Enabled = true
	f15.F1.Sound:Play()
	
	f16.F1.ParticleEmitter.Enabled = true
	f16.F1.Sound:Play()
	
	f17.F1.ParticleEmitter.Enabled = true
	f17.F1.Sound:Play()
	
	f18.F1.ParticleEmitter.Enabled = true
	f18.F1.Sound:Play()
	
end)



	
	
	
	
	
	
	
	
	



local button = script.Parent

local root = workspace:WaitForChild("FX")

button.MouseButton1Click:Connect(function()
	for _, descendant in ipairs(root:GetDescendants()) do
		if descendant:IsA("ParticleEmitter") then
			descendant.Enabled = true
		elseif descendant:IsA("Sound") then
			descendant.Play()
		end
	end
end)

A couple of issues with your solution, you should be using loops as it makes for better (more readable code) and doesn’t pollute the local environment with unnecessary local variable declarations, you should also be using the connection instance method :Connect() as its legacy variant :connect() has long been deprecated.

1 Like