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

How do you change particle emitter colors using buttons?

I'm trying to make a machine similar to NintendoZERG's smoke machine, but instead of smoke I'm trying to use particle emitters. Unfortunately unlike smoke, sparkles, fire, and even basic parts, the script doesn't seem to like the particle emitter very much. Is there a way to script the emitter to change colors based on the color of the buttons?

1 answer

Hello. I see what kind of machine you are trying to make. I can give you a few quick tips to get you started on the parts of the machine. First I will define any variables that I will use throughout this answer. The buttons will have ClickDetectors to get input. If you want to see the finished product you can look at this uncopylocked place: Particle Machine.

local machine = game.Workspace.Machine -- The model is named Machine in Workspace.
local emitter = machine.Emitter.ParticleEmitter -- The ParticleEmitter is in a Part named Emitter.
local purpleButton = machine.Purple.ClickDetector -- Purple Button
local blackButton = machine.Black.ClickDetector -- Black Button
local whiteButton = machine.White.ClickDetector -- White Button

As I said before, the buttons will have ClickDetectors to get input from the player's mouse. Now we will create the functions when each button is pressed. It's pretty obvious which button does what. Now sadly, ParticleEmitters don't accept plain Color3 values. They only accept ColorSequence values. The function will create a ColorSequence value with 2 points that are set to the color purple. I will give only one function for the purple button, and you can script the other two functions, as the Color3 values can be changed in the script itself.

EDIT: BaseParts now have Color3 values! Just use script.Parent.Color to define it's Color3 and call it instead of making your own Color3.

purpleButton.MouseClick:Connect(function() -- MouseClick is an event that comes with ClickDetector.
	emitter.Color = ColorSequence.new(Color3.new(170, 0, 255), Color3.new(170, 0, 255)) -- Change emitter color.
end)

With the last two functions in the script, everything would be finished. Don't forget the uncopylocked place here: Particle Machine. I hope you find this helpful and always have fun scripting and developing!

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