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

What is wrong with my color changing script?

Asked by 8 years ago
local balloonlight = script.Parent.PointLight
local randomnumber = math.random(4)

if randomnumber == 1 then
    script.Parent.BrickColor = BrickColor.Blue()
    balloonlight.Color = Color3(61, 87, 149)
end
if randomnumber == 2 then
    script.Parent.BrickColor = BrickColor.Red()
    balloonlight.Color = Color3(255, 0, 0)
end
if randomnumber == 3 then
    script.Parent.BrickColor = BrickColor.Yellow()
    balloonlight.Color = Color3(255, 233, 54)
end
if randomnumber == 4 then 
    script.Parent.BrickColor = BrickColor.Green()
    balloonlight.Color = Color3(33, 86, 27)
end

This script is supposed to change the color but it is always green, and the pointlight never changes color.

Thanks, RadioactiveSherbet

2 answers

Log in to vote
0
Answered by
Unlimitus 120
8 years ago

The reason that your Color3 won't work is because Color3 works with the numbers 0 through 1. To get the color red, you would do Color3.new(1, 0, 0) which is equivalent to 255, 0, 0

Here is what I would do:

--[[ Unlimitus ]]--

local balloonLight = script.Parent:WaitForChild("PointLight")
local colors = { -- Table full of colors
    "Bright blue",
    "Bright red",
    "Bright yellow",
    "Bright green"
}
local randomNumber = math.random(1, #colors) -- Pick a random number between 1 and the amount of colors in "colors"
local color = BrickColor.new(colors[randomNumber])
local color3 = color.Color -- Gets the Color3 value of a BrickColor

script.Parent.BrickColor = color
balloonLight.Color = Color3.new(color3.r, color3.g, color3.b)
Ad
Log in to vote
0
Answered by 8 years ago

Because you have math.random(4), correctly you should use math.random(1,4), It chooses a random number one through 4.

local balloonlight = script.Parent.PointLight
local randomnumber = math.random(1,4)

if randomnumber == 1 then
    script.Parent.BrickColor = BrickColor.Blue()
    balloonlight.Color = Color3.new(61, 87, 149)
elseif randomnumber == 2 then
    script.Parent.BrickColor = BrickColor.Red()
    balloonlight.Color = Color3.new(255, 0, 0)
elseif randomnumber == 3 then
    script.Parent.BrickColor = BrickColor.Yellow()
    balloonlight.Color = Color3.new(255, 233, 54)
elseif randomnumber == 4 then
    script.Parent.BrickColor = BrickColor.Green()
    balloonlight.Color = Color3.new(33, 86, 27)
end

Edit you are also missing .new for Color3 which requires Color3.new.

0
But how do I make the pointlight change color? RadioactiveSherbet 30 — 8y
0
Fixed. masternick1331 15 — 8y
0
thx RadioactiveSherbet 30 — 8y
0
Still doesnt work :( RadioactiveSherbet 30 — 8y

Answer this question