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.
In side of the Model “Fire”
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
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
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
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.
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
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.