Gui Colors not constantly changing

I am trying to change the GUI’s background color every 2.5 seconds here is my script

local colors = {
	red = Color3.fromRGB(255,0,4),
	blue = Color3.fromRGB(29,138,255),
	purple = Color3.fromRGB(81,23,255),
	orange = Color3.fromRGB(255,155,15)
}

while true do
	wait(1)
	for _,v in pairs(colors) do
		square.BackgroundColor3 = v
	end
end

and here is my first attempt when trying to do this:

while true do
	task.wait(2.1)
	square.BackgroundColor3 = Color3.fromRGB(255,0,4)
	task.wait(2.1)
	square.BackgroundColor3 = Color3.fromRGB(29, 138, 255)
	task.wait(2.1)
	square.BackgroundColor3 = Color3.fromRGB(81, 23, 255)
	task.wait(2.1)
	square.BackgroundColor3 = Color3.fromRGB(255, 155, 15)
end

Can you show the lines where “square” is defined?

local square = game.StarterGui.ColorSquare.TransparentBlackground.Square

“Square” is the name of the frame

Change that to:

local square = script.Parent

and place the script inside the frame itself. Make sure it’s a local script.

2 Likes
local colors = {
	"red" = Color3.fromRGB(255,0,4),
	"blue" = Color3.fromRGB(29,138,255),
	"purple" = Color3.fromRGB(81,23,255),
	"orange" = Color3.fromRGB(255,155,15)
}

while true do
	wait(1)
	for _,v in pairs(colors) do
		square.BackgroundColor3 = v
	end
end

Also the keys in the table should be string values (before they would have been recognised as variables, unless that was intentional).

Also, if you want each color to be visible, you may need to add a bit of delay to the loop. It’ll run through all the colors too quickly to see the way it is right now. sorry for formatting I’m on mobile

	"red" = Color3.fromRGB(255,0,4),
	"blue" = Color3.fromRGB(29,138,255),
	"purple" = Color3.fromRGB(81,23,255),
	"orange" = Color3.fromRGB(255,155,15)
}

while true do
	wait(1)
	for _,v in pairs(colors) do
-- Needs a wait or something, colors will flash too fast to be visible.
		square.BackgroundColor3 = v
	end
end```
1 Like

To help understanding the error, you tried changing the gui inside StarterGui. However, you have to access the players PlayerGui, since StarterGui is whatever GUI the player gets upon joining.

1 Like