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 make a button that turns off and on all particle emitters in my game?

I want to make a button that when you click it, it turns off particle effects and turns them on if you click it again. I have no idea how to though and I would like the responses to be descriptive like tell me what scripts to put in each part and etc.

1 comment

0

No.

2 answers

✓ Accepted answer

I made this script to delete all my fixers in my game.

repeat wait() until game:GetService("ContentProvider").RequestQueueSize == 0

function RecursiveGeneric(Parent, Func, ClassLimit)
	for _, Child in pairs(Parent:GetChildren()) do
		if not ClassLimit or Child:IsA(ClassLimit) then
			Func(Child)
		end
		RecursiveGeneric(Child, Func, ClassLimit)
	end
end

RecursiveGeneric(
	workspace,
	function(part)
		if part.Name == "Fixer" then
			part:Destroy()
		end
	end,
	"BasePart", "UnionOperation"
)

script:Destroy()

The important part is this:

function RecursiveGeneric(Parent, Func, ClassLimit)
	for _, Child in pairs(Parent:GetChildren()) do
		if not ClassLimit or Child:IsA(ClassLimit) then
			Func(Child)
		end
		RecursiveGeneric(Child, Func, ClassLimit)
	end
end

This is from an endorsed weld script. So if we do this:

function RecursiveGeneric(Parent, Func, ClassLimit)
	for _, Child in pairs(Parent:GetChildren()) do
		if not ClassLimit or Child:IsA(ClassLimit) then
			Func(Child)
		end
		RecursiveGeneric(Child, Func, ClassLimit)
	end
end

function SetAllEmitters(value)
	RecursiveGeneric(
		game.workspace,
		function(emitter)
			emitter.Enabled = value
		end,
		"ParticleEmitter"
	)
end

Then just use that function somewhere later in your script, like this:

SetAllEmitters(false)

1 comment

0

I also didn't notice it said "button". use the Touched event with my function. http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched

This is simple, just insert this script in a function like this

function ToggleParticles()
        --Insert my script here
end

--Use the ClickDetector script thing here

Also, insert ClickDetector in your on and off button

Roblox has been changing so much, so I don't know what the current ClickDetector script is. Ok, now lets get into the script. All you need to do is call all your particle emmitters and add this after ParticleEmitter, .Enabled = false Example:

--Insert your part/brick name at Part
--Insert your ParticleEmmiter name in ParticleEmmiter
game.Workspace.Part.ParticleEmmiter.Enabled = false

NOTE:Make sure each brick/part is a DIFFRENT NAME or else the script might/will mess up. So basically like this

function ToggleParticles()
game.Workspace.Part1.ParticleEmmiter.Enabled = false
game.Workspace.Part2.ParticleEmmiter.Enabled = false
game.Workspace.Part3.ParticleEmmiter.Enabled = false
end

Oh, forgot to tell you to insert the script in the off button. To do the on button, do the same just with Enabled = true instead of Enabled = false. Just a example,

function ToggleParticles()
game.Workspace.Part1.ParticleEmmiter.Enabled = true
game.Workspace.Part2.ParticleEmmiter.Enabled = true
game.Workspace.Part3.ParticleEmmiter.Enabled = true
end

Hope this helps!

6 comments

0

didnt work for me

0

sure you kept up with the ClickDetector script? I haven't, so I can't tell you.

0

I just posted a simple way

0

can you post the entire script and do I put it in what part i want to be the button and also do I use the click detector adavanced object aswell

0

Pretty sure I mentioned this, but the last script block was for the ON button and the second last script is for ON button

0

ya but nothing is working and i tried dif things so ya

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