Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I turn off particle emitters after a certain time?

Okay so I built this cannon and I'm doing some testing, I'm experimenting with muzzle flash. so this is the script for a button to "fire" the cannon, well more to check muzzle flash, screen shake, and sound.

What I'm having trouble with is that I'm trying to get the particles to be disabled after a certain time, I tried using wait() but it just broke the thing entirely.

I've been told to use a coroutine, I've attempted to do so but was not successful.

any help is appreciated

local ClickDetector = workspace.Part.ClickDetector
local button = script.Parent
local sound = game.Workspace:FindFirstChild("410mm")


function fire()
	
	sound:Play()
	sound.Looped = false
	local gun = game.Workspace:FindFirstChild("WEEBLYIOWA")
	
	local descendants = gun:GetDescendants()
	
	for _, v in pairs(descendants) do
		if v:IsA("ParticleEmitter") then
			v.Enabled = true
	
		end
	wait(4)
		v.Enabled = false
	end
end 

		
ClickDetector.MouseClick:connect(fire)

3 answers

✓ Accepted answer
local ClickDetector = workspace.Part.ClickDetector
local button = script.Parent
local sound = game.Workspace:FindFirstChild("410mm")


function fire()

    sound:Play()
    sound.Looped = false
    local gun = game.Workspace:FindFirstChild("WEEBLYIOWA")

    local descendants = gun:GetDescendants()

    for _, v in pairs(descendants) do
        if v:IsA("ParticleEmitter") then
            v:Emit(75) -- any number of particles you want emitted, probably around 50-100
	-- use wait() and emit again if you want more i guess
        end
    end
end 


ClickDetector.MouseClick:connect(fire)

1 comment

0

I posted the exact answer to my question an hour prior to this one, however I can't get my own answer to label the question as answered. I'll highlight this reply to help others. thanks

WELP

Guess everybody in my Discord are absolute braindeads.

this can be solved in the most simple way

instead of v:Enabled = true

I can just put

v.Emit()

1 comment

0

I was gonna suggest using spawn() but if that works well, then why mess with success?

You Could do this:

local ClickDetector = workspace.Part.ClickDetector
local button = script.Parent
local sound = game.Workspace:FindFirstChild("410mm")


function fire()

    sound:Play()
    sound.Looped = false
    local gun = game.Workspace:FindFirstChild("WEEBLYIOWA")

    local descendants = gun:GetDescendants()

    for _, v in pairs(descendants) do
        if v:IsA("ParticleEmitter") then
            v.Enabled = true

        end
    end
end 


ClickDetector.MouseClick:connect(fire)

And then have a script inside the particle emitter that says:

if script.parent.enabled = true then

wait(4)

script.parent.enabled = false

This discussion is preserved as it was. New answers, comments, and votes are closed.