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

How do I change the point light color in scripting?

I am trying to make a disco light. I have it set up so when I click a button a loop will happen and switch between colors. But in order for that to work I first need to find out how to change the pointlight color in a script. In order for me to set up the loop I need to figure this out first.

local Light9 = game.Workspace.Light9.PointLight

function onClicked(playerWhoClicked)
	Light9.Brightness = 100
	Light9.Range = 60
	Light9.Color --This is where I need help.
	
end
 
script.Parent.ClickDetector.MouseClick:connect(onClicked)


1 comment

0

If you want a simple solution you should be able to use, BrickColor.random().Color as this creates a random brick color then you just use the Color3 object of the brick. You will need to handle the looping part though.

2 answers

✓ Accepted answer

Color is a Color3 value. Set it by doing Light9.Color = Color3.new(red, green, blue), where the three colors are the rgb components of the color from 0 to 1.

To make those random, you can use math.random(), which returns a random value in the range [0, 1): Light9.Color = Color3.new(math.random(), math.random(), math.random()).

Alternatively, like kingdom5 said, you can get a random BrickColor and convert it into a Color3 by doing Light9.Color = BrickColor.Random().Color.

Quick note: If you are given values in the standard color range 0-255 like (255, 127, 63), you can make a Color3 out of those by simply dividing all of them by 255 to put them in the correct range: Color3.new(255/255, 127/255 , 63/255)

You need to give the man an example to really make ti go through man. c:

local light = game.Workspace.Part.PointLight

light.Color = Color3.new(4, 175, 250) --cyan

:p

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