Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make a disco PointLight I can't seem to get it?

Asked by 8 years ago

Ok here is what I have tried so far in the script

Light = script.Parent.Tile.PointLight.Color
while true do
wait (0.2)
Light.Color = Color.Random(0,0,0)
end

It is a normal script that is located inside a brick called Tile which has a PointLight in it .

3 answers

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

I'm not entirely sure that Color.Random() exists in Lua, but you can get the same affect by combining Color3 with math.random().

Also, line 1 references the Color property of the light. Did you mean to reference the light?

Light = script.Parent.Tile.PointLight
while true do
    wait (0.2)
    Light.Color = Color3.new(math.random(), math.random(), math.random())
end

Hope this helped.

Ad
Log in to vote
0
Answered by
0_0 70
8 years ago
**Light = script.Parent.Tile.PointLight.Color**
while true do
wait (0.2)
**Light.Color = Color.Random(0,0,0)**
end

You define the 'Light' variable ending with .Color and then attempt to do Light.Color which is basically doing

script.Parent.Tile.PointLight.Color.Color

Which wouldn't work and also Color.Random isn't a method. Here's how you should tackle something like this:

local Light = script.Parent.Tile.PointLight -- Defining the PointLight instance

while wait(0.2) do  -- Shorter than doing while true do wait(2) code end
local Random1 = math.random(255)
local Random2 = math.random(255)
local Random3 = math.random(255)
Light.Color = Color3.new(Random1/255,Random2/255,Random3/255)
end

I advice studying up on:

http://wiki.roblox.com/index.php?title=Random_numbers and http://wiki.roblox.com/index.php?title=Color3

All the best.

0
math.random() already returns a number between 0 & 1, so in this case it would be fine using just that. Pyrondon 2089 — 8y
0
Oh yeah, I've mostly been using /255 and completely forgot about that, thanks for the refresher. 0_0 70 — 8y
0
No problem. Pyrondon 2089 — 8y
Log in to vote
0
Answered by
Vrakos 109
8 years ago

Hello brandonkludke2,

Your question has already been answered, but I would just like to quickly clear some things up. There was an answer which suggested using math.random. This is a start for picking a random Color3 color, and does indeed bring more variety, BUT there is another method which has less variety, but is much easier to remember.

First of all, I recommend taking a look at the properties and constructors of BrickColor here.

We'll be using the Random constructor and the Color property.

Now, onto your script.

BrickColor.Random() Returns a random BrickColor. Adding .Color after the parenthesis would return the Color3 value of the BrickColor value.

local Light = script.Parent.Tile.PointLight.Color
while true do
wait (0.2)
Light.Color = BrickColor.Random().Color -- Random BrickColor and returning the Color3 value.
end

I hope this helped! If you found this helpful, please don't forget to accept this answer. -Vrakos

Answer this question