So, I have these fireworks, and I’m trying to edit the script to make them usable.
I was asked to edit the script so that the flames would turn on and off one after another in a loop, which is what I did, and it looks like this. The issue is: I can’t seem to stop the animation once the “on” button is clicked.
What I’m trying to achieve is the possibility of turning on and off the fireworks by clicking on the GUI button.
Here is the code:
script.Parent.MouseButton1Down:connect(function()
while true do
game.Workspace.Fire.S4.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S4.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S4.SurfaceLight.Brightness = 10
game.Workspace.Fire.S4.Sound:Play()
wait(0.5)
game.Workspace.Fire.S4.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S4.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S4.SurfaceLight.Brightness = 0
game.Workspace.Fire.S4.Sound:Pause()
game.Workspace.Fire.S3.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S3.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S3.SurfaceLight.Brightness = 10
game.Workspace.Fire.S3.Sound:Play()
game.Workspace.Fire.S5.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S5.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S5.SurfaceLight.Brightness = 10
game.Workspace.Fire.S5.Sound:Play()
wait(0.5)
game.Workspace.Fire.S3.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S3.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S3.SurfaceLight.Brightness = 0
game.Workspace.Fire.S3.Sound:Pause()
game.Workspace.Fire.S5.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S5.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S5.SurfaceLight.Brightness = 0
game.Workspace.Fire.S5.Sound:Pause()
game.Workspace.Fire.S2.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S2.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S2.SurfaceLight.Brightness = 10
game.Workspace.Fire.S2.Sound:Play()
game.Workspace.Fire.S6.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S6.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S6.SurfaceLight.Brightness = 10
game.Workspace.Fire.S6.Sound:Play()
wait(0.5)
game.Workspace.Fire.S2.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S2.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S2.SurfaceLight.Brightness = 0
game.Workspace.Fire.S2.Sound:Pause()
game.Workspace.Fire.S6.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S6.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S6.SurfaceLight.Brightness = 0
game.Workspace.Fire.S6.Sound:Pause()
game.Workspace.Fire.S1.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S1.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S1.SurfaceLight.Brightness = 10
game.Workspace.Fire.S1.Sound:Play()
game.Workspace.Fire.S7.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S7.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S7.SurfaceLight.Brightness = 10
game.Workspace.Fire.S7.Sound:Play()
wait(0.5)
game.Workspace.Fire.S1.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S1.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S1.SurfaceLight.Brightness = 0
game.Workspace.Fire.S1.Sound:Pause()
game.Workspace.Fire.S7.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S7.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S7.SurfaceLight.Brightness = 0
game.Workspace.Fire.S7.Sound:Pause()
end
end)
Now, I tried to use a debounce method using a boolean variable that is checked by an if statement everytime the button is clicked, but it didn’t work. For reference, I followed this Wiki article.
As second attempt, I tried using break loop, as specified on this other article but obviously it didn’t work either.
More recently I also tried using a BoolValue object, placed in the workspace, and the code looks like this:
local Firing = game.Workspace.Firing
local function Fire()
game.Workspace.Fire.S4.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S4.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S4.SurfaceLight.Brightness = 10
game.Workspace.Fire.S4.Sound:Play()
wait(0.5)
game.Workspace.Fire.S4.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S4.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S4.SurfaceLight.Brightness = 0
game.Workspace.Fire.S4.Sound:Pause()
game.Workspace.Fire.S3.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S3.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S3.SurfaceLight.Brightness = 10
game.Workspace.Fire.S3.Sound:Play()
game.Workspace.Fire.S5.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S5.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S5.SurfaceLight.Brightness = 10
game.Workspace.Fire.S5.Sound:Play()
wait(0.5)
game.Workspace.Fire.S3.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S3.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S3.SurfaceLight.Brightness = 0
game.Workspace.Fire.S3.Sound:Pause()
game.Workspace.Fire.S5.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S5.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S5.SurfaceLight.Brightness = 0
game.Workspace.Fire.S5.Sound:Pause()
game.Workspace.Fire.S2.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S2.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S2.SurfaceLight.Brightness = 10
game.Workspace.Fire.S2.Sound:Play()
game.Workspace.Fire.S6.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S6.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S6.SurfaceLight.Brightness = 10
game.Workspace.Fire.S6.Sound:Play()
wait(0.5)
game.Workspace.Fire.S2.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S2.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S2.SurfaceLight.Brightness = 0
game.Workspace.Fire.S2.Sound:Pause()
game.Workspace.Fire.S6.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S6.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S6.SurfaceLight.Brightness = 0
game.Workspace.Fire.S6.Sound:Pause()
game.Workspace.Fire.S1.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S1.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S1.SurfaceLight.Brightness = 10
game.Workspace.Fire.S1.Sound:Play()
game.Workspace.Fire.S7.ParticleEmitter1.Enabled = true
game.Workspace.Fire.S7.ParticleEmitter2.Enabled = true
game.Workspace.Fire.S7.SurfaceLight.Brightness = 10
game.Workspace.Fire.S7.Sound:Play()
wait(0.5)
game.Workspace.Fire.S1.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S1.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S1.SurfaceLight.Brightness = 0
game.Workspace.Fire.S1.Sound:Pause()
game.Workspace.Fire.S7.ParticleEmitter1.Enabled = false
game.Workspace.Fire.S7.ParticleEmitter2.Enabled = false
game.Workspace.Fire.S7.SurfaceLight.Brightness = 0
game.Workspace.Fire.S7.Sound:Pause()
Firing.Value = false
end
script.Parent.MouseButton1Down:Connect(function()
Firing.Value = true
while Firing do
Fire()
if not Firing then
break
end
end
end)
Script 2:
script.Parent.MouseButton1Click:Connect(function()
game.Workspace.Firing.Value = false
end)
If someone could please explain what I did wrong and how to achieve what I need, that would be great.