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

How to randomize the color of a light?

Asked by 7 years ago

How the scriptlooks like:

local screen = script.Parent local light = script.Parent.SpotLight

while true do local random1 = math.random(0,255)
local random2 = math.random(0,255) local random3 = math.random(0,255) screen.Color = Color3.new(random1,random2,random3) light.Color = Color3.new(random1,random2,random3) wait(1) end

How it looks like in Workspace: https://gyazo.com/04c277a749b5046465299296ae15a511

The screen works fine and dandy but the light just get ridiculous numbers like 231321,839128,832189123

I need help, I am desperate.

1 answer

Log in to vote
1
Answered by
thesit123 509 Moderation Voter
7 years ago

There is 2 known ways of fixing this issue:

1 - Using BrickColors and BrickColors.Random instead of Color3 values:

while true do
    script.Parent.light.BrickColor = BrickColor.random()
    wait(1)
end

2 - Using .fromRGB instead of .new:

while true do
    local R = math.random(0, 255)
    local G = math.random(0, 255)
    local B = math.random(0, 255)

    script.Parent.light.Color3 = Color3.fromRGB(R, G, B)
    wait(1)
end
Ad

Answer this question