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

How to change color continuously? [UNANSWERED]

I am trying to make a script where the color of the brick changes continuously no matter what happens. And when the color reaches white (R/255, G/255, B/255) it will start going down in colors. Here is a script,

local script = script.Parent

while true do
	script.BrickColor = BrickColor3.new(R/+1, G/+1, B/+1) -- don't know what to put here...
	if script.BrickColor = R/255, G/255, B/255 then
		for i = 1, 255 do
			script.BrickColor = BrickColor3.new(R/-1, G/-1, B/-1)
		end
	end
end

2 answers

✓ Accepted answer

Structure

There's a much simpler structure:

  • Go up from 0 to 255

  • Go down from 255 to 0

  • (Repeat)

Here's what that would look like:

while true do
	for bright = 0, 1, 0.03 do
		-- Set color...
		wait()
	end
	for bright = 1, 0, -0.03 do
		-- Set color...
		wait()
	end
end

Setting BrickColor

The BrickColor.new constructor can take a Color3 value. Color3 values use an R, G, and B ranging from 0 to 1 (not 0 to 255 as is reported by the Properties tab). So this could look like

local brick = script.Parent -- DO NOT REDEFINE SCRIPT
-- That is a wonderful way to confuse yourself

...
		brick.BrickColor = BrickColor.new( Color3.new( bright, bright, bright ) )
...

Not Using BrickColor? (Getting it continuous)

So, this will more or less work. The problem is that BrickColors are ultimately discrete. There are only a handful of them, it won't actually be a smooth transition.

There isn't a simple solution to this.

At this point, there are two solutions.

SpecialMesh: The trick I came up with a number of years ago. Using a FileMesh, you can modify the VertexColor property (which is a Vector3, not a Color3) when it has a pure white texture to get the mesh to be that color.

I had MeshDB upload this brick mesh that is 0.5x0.5x0.5. Set its Scale to be twice the size of the brick, e.g.,

brick.Mesh.Scale = brick.Size * 2

Then set its VertexColor:

...
		brick.Mesh.VertexColor = Vector3.new( bright, bright, bright )
...

(Remember it needs a pure white TextureId -- upload one yourself or just search "White" on decals)


GUIs: The other option is to use 6 different SurfaceGuis. This requires more instances, and will ignore lighting.

Color3 values can range from 0 to 1. You can find your colors by dividing the values you want by 255.

You can combine BrickColor and Color3 constructors into one:

game.Workspace.Part.BrickColor = BrickColor.new(Color3.new(1,1,1))

At least, that's what Wiki said.

Another way you can change colors continuously is to try:

game.Workspace.Part.BrickColor = BrickColor.Random()

Don't forget to use wait(--[[WaitTime]])in your while loop, lol.

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