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

colour changing script wont change colour values?

i have a script that should change two colour values, a brick colour and a color3 value, but the script doesnt change them, and i dont exactly know why

script:

z = {"1","2","3","4","5"}

while true do
wait(129)
script.Parent.Value = (z[math.random(1,#z)])
wait(0.1)

if script.Parent.Value == "1" then
script.Parent.Parent.Colour.Value = "Royal Purple"
script.Parent.Parent.ColourMisc.Value = "98, 37, 209"

elseif 
script.Parent.Value == "2" then
script.Parent.Parent.Colour.Value = "Hot pink"
script.Parent.Parent.ColourMisc.Value = "255, 0, 191"

elseif 
script.Parent.Value == "3" then
script.Parent.Parent.Colour.Value = "Steel blue"
script.Parent.Parent.ColourMisc.Value = "82, 124, 174"

elseif 
script.Parent.Value == "4" then
script.Parent.Parent.Colour.Value = "Pastel blue-green"
script.Parent.Parent.ColourMisc.Value = "159, 243, 233"

elseif 
script.Parent.Value == "5" then
script.Parent.Parent.Colour.Value = "Neon orange"
script.Parent.Parent.ColourMisc.Value = "213, 115, 61"


	
end
end

8 comments

0

Color3 values must be given a Color3. ¨0, 0, 0¨ is a string, not a Color3. You can do Color3.new(0, 0, 0) to assign it to a Color3. Do the same with BrickColor values, except give them BrickColors like BrickColor.new(¨Royal Purple¨).

0

so it would be script.Parent.Parent.Colour.Vaule = BrickColor.new("Royal purple") and script.Parent.Parent.ColourMisc.Value = Color3.new(98,37,209) ?

0

do you notice that ur using "colour" and not "color"?; aslo you would have to extract values from the strings in order to make valid roblox colors

0

yeah i know im using colour, Im using Color bool values named "Colour" and "ColourMisc"

0

Its all confusing and i dont understand where i went wrong

0

*BrickColorValue and a Color3Value

0

One thing, did you wait 129.1 seconds? wait(129)

If you did wait 129.1 seconds, why don't you use the Value instance instead of StringValue?

Like using BrickColorValue for BrickColors and Color3Value for Color3s

Oh, and check spelling of BrickColors

0

no i waited 129 seconds, then the extra 0.1 after

2 answers

✓ Accepted answer

well there is multiple problems with your code:

1.) it uses colour but roblox uses color

2.) some color values aren't valid Roblox color Values for instance: if you wanted to make a brick really red you would have to write the following code

local part = workspace.part
part.BrickColor = BrickColor.new("Really red")

Do you notice that really red is write as "Really red" and not "Really Red"; that's a convention that all roblox "string color values" follow; so Royal Purple would be "Royal purple"

alternatively to the previous code; you can use Red Green Blue(RGB) values to make make the same effect: example:

local part = workspace.part
part.Color = Color3.new(255,0,0);

the first argument to Color3.new is amount of red, the second one is green and finally the one is blue.

here is one possible way to remake your code: please note: this is not in the best form in which it could be; so criticism is taken offensively you will have to adjust the code to fit your setup since i don't actually know your setup

local colors = {
	{
		"Royal purple",
		{98, 37, 209}
		
	},

	{
		"Hot pink",
		{255, 0, 191}
		
	};

	
	{
		"Steel blue",
		{82, 124, 174}
		
	};

	{
		"Pastel blue-green",
		{ 159, 243, 233}
		
	};

	{
		"Neon orange",
		{213, 115, 61}
		
	};
	
}


local brickColor_Object = script.Parent.Parent.Colour -- change to true directory of the object that's suppose to hold the brick color value

local color3_object = script.Parent.Parent.ColourMisc -- change to true directory of the object that's suppose to hold the color3 value

while true do
wait(129)
local color_index = math.random(1,#colors)
wait(0.1)



brickColor_object.Value = colors[color_index][1]

local RGB_values = color[color_index][2]
local red = RGB_values[1]
local green = RGB_values[2]
local blue = RGB_values[3]
color3_object.Value= Color3.new(red,green,blue)


end

Again, Adjust the code to fit your setup!

so the above code will wait every 129 seconds then it will choose a random number between 1 and the quantity of colors in the table colors. then it will wait 0.1 seconds and will apply the values at the index of the randomly chosen number on the BrickColor value held in the variable brickColor_Object

i assume that you understand the rest bcz it's self explainatory

22 comments

0

I use Colour instead of color, and the spelling doesnt matter because its the name of the colorvalues im using, if i didnt rename it it would just be Value.Value

0

well; idk your setup so I have to assume most things; it could've helped if you renamed it something obvious but diffrent

0

and basically this script is inside of a bool value, and this script pretty much generates a number 1-5 every 129 seconds,then after 0.1 seconds it should check to see what number was chosen, each number having a colour (color -_-) assigned to it. once it has the found the number, the color name and the color3 should be put into two other values called "Colour" and "ColourMisc"

0

after that, a main script uses those two values to recolour (recolor) brick colours inside of a model, and the light colours

0

well; there is lots of unnecessary steps; but the Which object of the two - Colour and ColourMisc - holds the text color name and which one holds the RGB values

0

Colour holds the colour name and ColourMisc holds the RBG values

0

so just to make sure; Colour is a string Value object and ColourMisc is a color3 value object right?

0

im sorry but its all so confusing and i legit have no idea what to do

0

just answer my question and i can help

0

i undertand that programming can be quite difficult for beginners; but that's why this website exists

0

No Colour is a BrickColorValue

0

okay

0

i am going to shorten ur script a bit

0

alright

0

hopefully the code is a bit clear to you; read the edited answer closely and ask me whatever you don't understand

0

From what I see, this is just becoming unnecessarily complicated. See my answer

0

no its not dude; this is actually really simple

0

thankyou both for helping, i tried both, i didnt understand why Arsubia's script didnt work, but i am hugely greatful for all the help, f i could accept both of the answers i would

0

thankyou both

0

no problem; i recommend going to https://www.lua.org/pil/1.html and going through the lessons to learn more

0

i dont get it. can u reword that??

0

nevermind

math.randomseed(tick()) --Makes the colors truly random
PartsToTurnColor = {} --Insert instances of the parts you want to change color here
Colors = {Color3.new(98, 37, 209),Color3.new(255, 0, 191),Color3.new(82, 124, 174),Color3.new(159, 243, 233),Color3.new(213, 115, 61)}

while wait(129) do
	color = Colors[math.random(1,#Colors)]
	for _,v in pairs(PartsToTurnColor) do
		v.Color = color
	end
end

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