Color changing light

So I’m currently trying to script a light that changes color.


So I have a brick with a surface light and I am currently trying to create a scrip that changes the color of the light so the pool could then changes colors. How would I go on doing this? Any help is thankful!

2 Likes

Are you wanting to just change that 1 Brick’s Color for the Water & Light to change? If so, I believe you can look at this?
Environments and Terrain Tools) (Thanks ROBLOX)

No, I have a surface light and im trying to make the surface light thats in the water change colors so then the pool changes colors.

If that makes sense the light = the pool color so I’m trying to make the light auto-rotate between colors.

You can change the surface light colour.

surfaceLight.Color = Color3.New(color)

If you want to have all the lights together, then put them in a folder and then use a for loop to loop through each light and change the colour.

Is that how I make the surface light auto rotate colors from a rainbow for example/

Thats how you color the surface lights. It wont rotate colors.

How do I make it rotate colors?

You can do a loop to make it rotate colors

Well to make them change to like a rotation, you could use a loop, again to rotate the colours.

local t = 5; --how long does it take to go through the rainbow

while wait() do
	local hue = tick() % t / t
	local color = Color3.fromHSV(hue, 1, 1)
	--> set the color
end

Sourced: How to create a simple rainbow effect using TweenService

Example can be

while wait(1) do

SurfaceLight.Color = Color3.new(math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255)

end

It changes to a random color every second

2 Likes

and id replace math random with the light id correct?

You could probably do something relevant like this?

local SurfaceLight = workspace.Part.SurfaceLight
local Speed = 1

for Loop = 0, 1, 0.001 * Speed do 
    SurfaceLight.Color = Color3.fromHSV(Loop, 1, 1)
    wait()
end

No, replace the SurfaceLight part with the location of your surface light. The math.random is the random colour generated to make the rainbow effect.

I dont recommend while true do cause of lag

So I added this script to the surface light and nothings happening? Am I suppose to replace something?

while wait(0.25) do
    script.Parent.Color = Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255))
end

Is there a way to make it a bit smooth and have it fade into the next color?

Jackscarlett posted code above that would do a smooth transition

1 Like

You can use TweenService for that.

local TweenService = game:GetService('TweenService')

while true do
local tween = TweenService:Create(script.Parent, TweenInfo.new(.35), {Color = Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255))})
tween:Play()

tween.Completed:Wait()
end
2 Likes