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

How to make a Point Light change to a random color every 1 second?

Asked by
Nidoxs 190
9 years ago

Why wont this work?

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

2 answers

Log in to vote
3
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

You were a bit close. The part of line 2 that is incorrect, is after the equal sign. You only need to put Color3.new(), not the whole hierarchy. The only time you'd do that is if you're making a pointlight equal to another pointlight (Or other Color3 Value)'s color. So, here's your fixed script:

while true do -- An alternate to this is while wait(1) do
    script.Parent.PointLight.Color = Color3.new(math.random(),math.random(),math.random()) -- Be sure hierarchy is correct.
    wait(1)
end
Ad
Log in to vote
0
Answered by 9 years ago

It because line 2 doesn't equal anything thus causing it to stop running, so this is the fixed code:

while true do   
script.Parent.Color = Color3.new(math.random(), math.random(), math.random())
wait(1)
end

if this helped accept it as answer and if you have any other problems leave a comment!

Answer this question