Point light random color changer

i made this script which should just slowly fade between these random made colors but it doesnt work.

local light = script.Parent
local part = light.Parent
local repeating = true
local color1 = Color3.fromRGB(0, 11, 175)
local color2 = Color3.fromRGB(84, 0, 127)
local color3 = Color3.fromRGB(186, 0, 34)
local color4 = Color3.fromRGB(194, 189, 35)
local color5 = Color3.fromRGB(126, 208, 19)
local color6 = Color3.fromRGB(159, 16, 198)
local color7 = Color3.fromRGB(194, 42, 111)

function colorchanging()
	light.Color = Random(color1, color2, color3, color4, color5, color6, color7)
	
end

while repeating == true do
	colorchanging()
end

locations:
image

2 Likes

There’s no such function as Random(), so this obviously won’t be working

local light = script.Parent
local part = light.Parent
local repeating = true
local Colors = {
	Color3.fromRGB(0, 11, 175),
	Color3.fromRGB(84, 0, 127),
	Color3.fromRGB(186, 0, 34),
	Color3.fromRGB(194, 189, 35),
	Color3.fromRGB(126, 208, 19),
	Color3.fromRGB(159, 16, 198),
	Color3.fromRGB(194, 42, 111)
}


local function ChangeColor()
	local Color = Colors[math.random(1, #Colors)]
	light.Color = Color
end

while repeating do
	ChangeColor()
	task.wait(0.5)
end

A few notes:

  • You tried to make a while loop without any yielding, which would cause a crash
  • You shouldn’t be storing data that should be chosen randomly in lots of variables, a single table would be enough
2 Likes

If you wanna change slowly to an other color you will need to use Tweenservice if you want it to change smoothly

And also using random() isn’t going to work you will need to use a table to fix that issue like the person above

2 Likes

im so confused on how tweenservice works, i looked it up and i have no idea how to add it to my script,

(updated script):

local light = script.Parent
local part = light.Parent
local repeating = true
local Colors = {
	Color3.fromRGB(0, 11, 175),
	Color3.fromRGB(84, 0, 127),
	Color3.fromRGB(186, 0, 34),
	Color3.fromRGB(194, 189, 35),
	Color3.fromRGB(126, 208, 19),
	Color3.fromRGB(159, 16, 198),
	Color3.fromRGB(194, 42, 111),
	Color3.fromRGB(124, 255, 1),
	Color3.fromRGB(255, 149, 1),
	Color3.fromRGB(166, 48, 13)
}


local function Change()
	local Color = Colors[math.random(1, #Colors)]
	light.Color = Color
	local brightness = math.random(0.1, 1.7)
	light.Brightness = brightness
end

while repeating do
	Change()
	task.wait(0.5)
end
1 Like
local randomObject = Random.new(tick())

local light = script.Parent
local part = light.Parent

local function changeLight()
	light.Color = Color3.fromRGB(randomObject:NextInteger(1, 255), randomObject:NextInteger(1, 255), randomObject:NextInteger(1, 255))
	light.Brightness = randomObject:NextNumber(0, 2)
end

while true do
	changeLight()
	task.wait(0.5)
end
1 Like
local tweens = game:GetService("TweenService")

local light = script.Parent

while true do
	local tween = tweens:Create(light, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true, 0), {Color = Color3.new(1, 0, 0), Brightness = 5})
	tween:Play()
	tween.Completed:Wait()
	local tween = tweens:Create(light, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true, 0), {Color = Color3.new(0, 1, 0), Brightness = 5})
	tween:Play()
	tween.Completed:Wait()
	local tween = tweens:Create(light, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true, 0), {Color = Color3.new(0, 0, 1), Brightness = 5})
	tween:Play()
	tween.Completed:Wait()
end

Use of tween service.

https://gyazo.com/a0937e8be9d946ce67eaddbd07bec421

1 Like
local randomObject = Random.new(tick())

local tweens = game:GetService("TweenService")

local light = script.Parent

while true do
	local tween = tweens:Create(light, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true, 0), {Color = Color3.fromRGB(randomObject:NextInteger(0, 255), randomObject:NextInteger(0, 255), randomObject:NextInteger(0, 255)), Brightness = randomObject:NextNumber(5, 10)})
	tween:Play()
	tween.Completed:Wait()
	local tween = tweens:Create(light, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true, 0), {Color = Color3.fromRGB(randomObject:NextInteger(0, 255), randomObject:NextInteger(0, 255), randomObject:NextInteger(0, 255)), Brightness = randomObject:NextNumber(5, 10)})
	tween:Play()
	tween.Completed:Wait()
	local tween = tweens:Create(light, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true, 0), {Color = Color3.fromRGB(randomObject:NextInteger(0, 255), randomObject:NextInteger(0, 255), randomObject:NextInteger(0, 255)), Brightness = randomObject:NextNumber(5, 10)})
	tween:Play()
	tween.Completed:Wait()
end

And a hybrid implementation of both tweens and randomness.

It isn’t that complicated I will show you how here!

local TweenService = game:GetService("TweenService") -- Get tweenservice

local light = script.Parent
local part = light.Parent
local repeating = true
local Colors = {
	Color3.fromRGB(0, 11, 175),
	Color3.fromRGB(84, 0, 127),
	Color3.fromRGB(186, 0, 34),
	Color3.fromRGB(194, 189, 35),
	Color3.fromRGB(126, 208, 19),
	Color3.fromRGB(159, 16, 198),
	Color3.fromRGB(194, 42, 111),
	Color3.fromRGB(124, 255, 1),
	Color3.fromRGB(255, 149, 1),
	Color3.fromRGB(166, 48, 13)
}

local tweeninfo = TweenInfo.new(
	0.5,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.InOut,
	0,
	true,
	0
)

local function Change()
	local Color = Colors[math.random(1, #Colors)]
	
	local Tween = TweenService:Create(light, tweeninfo, {Color = Color}) -- create the tween
	Tween:Play() -- Play the tween
	repeat wait() until Tween.Completed -- wait until the tween completed 
	
	local brightness = math.random(0.1, 1.7)
	light.Brightness = brightness
end

while repeating do
	Change()
	task.wait(0.5)
end