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

What is wrong with my color changing script?

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

✓ Accepted answer

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)

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.

4 comments

0

But how do I make the pointlight change color?

0

Fixed.

0

thx

0

Still doesnt work :(

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