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

Why does this basic script now work? "Bad argument to #3 Color" is the error

I made this script, that's supposed to change the color of the particles emitted every 3 seconds, and then go back to normal. But nothing is going right. Here's the script:

local p1 = game.Workspace.particles.p1.ParticleEmitter
local p2 = game.Workspace.particles.p2.ParticleEmitter
while true do
	wait(3)
	p1.Color = Color3.new(0,0,0)
	p2.Color = Color3.new(0,0,0)
	wait(3)
	p1.Color = Color3.new(0,255,255)
	p2.Color = Color3.new(0,255,255)
end

What have I done wrong? All help is appreciated!

3 answers

✓ Accepted answer

##Problem

The ParticleEmitter's Color property is not a Color3 value. It's a ColorSequence.


##Solution

You would have to manipulate the ColorSequence to your favor.

  • You can have one argument being the only color that will be emitted.
game.Workspace.Part.ParticleEmitter.Color = ColorSequence.new(Color3.new(1,0,0))
  • You can have two arguments for transitioning from one color to the other.
game.Workspace.Part.ParticleEmitter.Color = ColorSequence.new(Color3.new(1,0,0), Color3.new(0,0,1))
  • Or you can have an array of multiple ColorSequenceKeypoints to allow adjustment of colors and timing.
game.Workspace.Part.ParticleEmitter.Color = ColorSequence.new({
    ColorSequenceKeypoint.new(0, Color3.new(1,0,0)),
    ColorSequenceKeypoint.new(.5, Color3.new(0,1,0)),
    ColorSequenceKeypoint.new(1, Color3.new(0,0,1))
})

What ColorSequenceKeypoint.new() will do is take the time between 0 and 1 of which the particle will change. It will then take the Color3 value as the second argument and transition the first color by that time.


##Note

Color3.new() will only take float values between 0 and 1. If you have any value higher, the Color in that category will be at 1. One way to solve this is to divide all three color values by 255. If you wish to use integers between 0 and 255 with Color3, use Color3.fromRGB().

For the sake of fixing your script, I will just transfer all the Colors to the basic sequence and I will convert Color3.new() to Color3.fromRGB().


##Final Script

local p1 = game.Workspace.particles.p1.ParticleEmitter
local p2 = game.Workspace.particles.p2.ParticleEmitter
while true do
    wait(3)
    p1.Color = ColorSequence.new(Color3.fromRGB(0,0,0)) --Use ColorSequence for the Color value of ParticleEmitters. Also, use Color3.fromRGB() to use values from 0 to 255
    p2.Color = ColorSequence.new(Color3.fromRGB(0,0,0))
    wait(3)
    p1.Color = ColorSequence.new(Color3.fromRGB(0,255,255))
    p2.Color = ColorSequence.new(Color3.fromRGB(0,255,255))
end

######Hopefully this answered your question, if it did do not forget to hit the accept answer button. If you have any questions, feel free to comment and I will get back to you.

1 comment

0

Thanks! That worked.

I tried out myself, and got help from the wiki.

Working script:

local p1 = game.Workspace.particles.p1.ParticleEmitter
local p2 = game.Workspace.particles.p2.ParticleEmitter

while true do
    wait(3)
    p1.Color = ColorSequence.new(Color3.new(0,0,0), Color3.new(0,0,0))
    p2.Color = ColorSequence.new(Color3.new(0,0,0), Color3.new(0,0,0))
    wait(3)
    p1.Color = ColorSequence.new(Color3.new(0,255,255), Color3.new(0,255,255))
    p2.Color = ColorSequence.new(Color3.new(0,255,255), Color3.new(0,255,255))
end

For more assistance look on the wiki.

Did you try changing Wait time?

1 comment

0

That wouldn't change much, I don't think. Besides, I still want it to be 3 seconds. I'll try it now though.

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