Dark/Light mode`

Im making it so it changes the background color to a dark/light mode. I cant figure out how to do it, also if you have any suggestions for it comment below.

edit:
i figured it out, but how should i improve it?
https://gyazo.com/d78cf5a55067db97be68760949c20081

So have you already scripted it and are having issues with it or are you asking us to script it for you? Oh wait you figured it out didn’t notice.

I have it scripted, im asking how to improve the script. Which can be found here:

local Click = script.Parent
local Background = game.Players.LocalPlayer.PlayerGui.Background2.Background
local SFrame = game.Players.LocalPlayer.PlayerGui.Background2.Script
local BFrame = game.Players.LocalPlayer.PlayerGui.Background2.Building
local UIFrame = game.Players.LocalPlayer.PlayerGui.Background2.UI
local GFXFrame = game.Players.LocalPlayer.PlayerGui.Background2.GFX


Click.MouseButton1Down:Connect(function()
	Background.BackgroundColor3 = Color3.new(0.960784, 0.960784, 0.960784)
	SFrame.BackgroundColor3 = Color3.new(0.854902, 0.854902, 0.854902)
	BFrame.BackgroundColor3 = Color3.new(0.854902, 0.854902, 0.854902)
	UIFrame.BackgroundColor3 = Color3.new(0.854902, 0.854902, 0.854902)
	GFXFrame.BackgroundColor3 = Color3.new(0.854902, 0.854902, 0.854902)

end)

Im trying to change all the OTHER ui exept the background to a diff color, note thats not all the ui

Hi jackthehunter25!

edit:
i figured it out, but how should i improve it?

If you’re purely looking for feedback on how to improve it design wise, this is the wrong category. Try posting your creation in the Cool Creations category.

I have it scripted, im asking how to improve the script. Which can be found here:

I suggest having a table with all of your gui elements you’d like to change. Loop through the table and set the background color to a predefined color. An example is below.

local guiElementsTable = {}; -- our gui elements table
local playerInstance = game:GetService("Players").LocalPlayer;

local lightColor = Color3.new(); -- light color here
local darkColor = Color3.new(); -- dark color here

for _, element in pairs(playerInstance.PlayerGui.Background2:GetChildren()) do
-- should also check to make sure element is a frame, text label, etc
table.insert(guiElementsTable, #guiElementsTable+1, element); -- add the element to the table
end

local lightMode = function()
for _, element in pairs(guiElementsTable) do
element.BackgroundColor3 = lightColor;
end
end

local darkMode = function()
for _, element in pairs(guiElementsTable) do
element.BackgroundColor3 = darkColor;
end
end
1 Like

You could make it a little darker, and with more shadows.

@jackthehunter25

Dont use Color3.new()
Use Color3.fromRGB()

Using the 2nd one allows for you to use the rgb color code, so basically you could do Color3.fromRGB(1, 1, 1)
And it will do 1 of each color, doing a really dark black

Sorry mobile, 2nd*