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

Making this script more efficient and smoother?

I've got a script that changes the lights randomly, but I'm trying to get it to transition smoothly for example,

if the first color was 255/255/255 and then the second color was 253/252/254 it would go

254/254/254
253/253/254
253/252/254

And then when it reaches the next color, it changes color after 3 seconds.

My current script.

A = game.Workspace.WallReception:GetChildren()

while true do
	colora = math.random(0,255)
	colorb = math.random(0,255)
	colorc = math.random(0,255)
	for i,v in pairs(A) do
		v.SurfaceLight.Color = Color3.new(colora/255,colorb/255,colorc/255)
		v.SurfaceGui.TextLabel.BackgroundColor3 = Color3.new(colora/255,colorb/255,colorc/255)
	end
	wait(3)
end

2 answers

✓ Accepted answer

In order to do this, you'll need to do some sort of interpolation between the colors.

The easiest way to do this would be to do a simple linear interpolation between each RGB color component. However, this can make for some fairly displeasing intermediate colors.

A better way to do it would be to convert to a different color space to give more vibrant and appealing intermediate colors.

Take a look at my answer on this question for an in-depth overview and comparison of linear RBG interpolation and linear HSV interpolation.

2 comments

0

Sweet

Instead of making three variables, make one using Color3.new

Lines 4, 5, and 6 can be combined like this,

local color = Color3.new(math.random(255)/255,math.random(255)/255,math.random(255)/255)

Now to use this with the rest of the script we simply do,

A = game.Workspace.WallReception:GetChildren()

while true do
	local color = Color3.new(math.random(255)/255,math.random(255)/255,math.random(255)/255)
    for i,v in pairs(A) do
        v.SurfaceLight.Color = color
        v.SurfaceGui.TextLabel.BackgroundColor3 = color
    end
    wait(3)
end

That would simplify this a bit.

That should work.

Good Luck!

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