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

Why won't my random color changer work?

I'm trying to make a button that changes the color of surface GUIs, but it doesn't do anything.

local button = script.Parent

 color = math.random(1,4)

button.MouseButton1Down:connect(function()
	if color == 1 then
		script.Parent.BackgroundColor3.new(40,40,40)
		script.Parent.Parent.Parent.Taskbar.BackgroundColor3.new(40,40,40)
		script.Parent.Parent.Parent.Taskbar2.BackgroundColor3.new(40,40,40)
		script.Parent.Parent.Parent.ImageLabel2.BackgroundColor3.new(40,40,40)
		script.Parent.Parent.Parent.StartMenu.BackgroundColor3.new(40,40,40)
		script.Parent.Parent.Parent.Settings.BackgroundColor3.new(40,40,40)
		
		
	if color == 2 then
		script.Parent.BackgroundColor3.new(255,0,0)
		script.Parent.Parent.Parent.Taskbar.BackgroundColor3.new(255,0,0)
		script.Parent.Parent.Parent.Taskbar2.BackgroundColor3.new(255,0,0)
		script.Parent.Parent.Parent.ImageLabel2.BackgroundColor3.new(255,0,0)
		script.Parent.Parent.Parent.StartMenu.BackgroundColor3.new(255,0,0)
		script.Parent.Parent.Parent.Settings.BackgroundColor3.new(255,0,0)
	
	if color == 3 then
		script.Parent.BackgroundColor3.new(0,255,0)
		script.Parent.Parent.Parent.Taskbar.BackgroundColor3.new(0,255,0)
		script.Parent.Parent.Parent.Taskbar2.BackgroundColor3.new(0,255,0)
		script.Parent.Parent.Parent.ImageLabel2.BackgroundColor3.new(0,255,0)
		script.Parent.Parent.Parent.StartMenu.BackgroundColor3.new(0,255,0)
		script.Parent.Parent.Parent.Settings.BackgroundColor3.new(0,255,0)
	
	if color == 4 then
		script.Parent.BackgroundColor3.new(0,0,255)
		script.Parent.Parent.Parent.Taskbar.BackgroundColor3.new(0,0,255)
		script.Parent.Parent.Parent.Taskbar2.BackgroundColor3.new(0,0,255)
		script.Parent.Parent.Parent.ImageLabel2.BackgroundColor3.new(0,0,255)
		script.Parent.Parent.Parent.StartMenu.BackgroundColor3.new(0,0,255)
		script.Parent.Parent.Parent.Settings.BackgroundColor3.new(0,0,255)
	end
end

Thanks if you can help, I'm also a bit of a noob at scripting.

1 answer

One can set the Color3 of a Gui like so.

gui.BackgroundColor3 = Color3.fromRGB(0,0,255)

Make note, the code you have above would error. Please, have the output window open at all times.

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