I’m trying to make a dark mode for people who don’t want to have the light mode, but the script has an error and I’m a beginner for scripting, it’s a normal script.
Edit: Another problem from changing it back to light mode is saying “If” is wrong.
Image:
local Website = script.Parent.Parent.Parent
local player = game.Players.LocalPlayer
local Create = script.Parent.Parent.Parent.Create
local Friends = script.Parent.Parent.Parent.Friends
local Games = script.Parent.Parent.Parent.Games
local Home = script.Parent.Parent.Parent.Home
local Settings = script.Parent.Parent.Parent.Settings
script.parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Parent.DarkMode.Value == false then
wait (0.1)
Create.BackgroundColor3 = Color3.fromRGB(6, 5, 34)
Friends.BackgroundColor3 = Color3.fromRGB(6, 5, 34)
Games.BackgroundColor3 = Color3.fromRGB(6, 5, 34)
Home.BackgroundColor3 = Color3.fromRGB(6, 5, 34)
Settings.BackgroundColor3 = Color3.fromRGB(6, 5, 34)
script.Parent.Parent.Parent.DarkMode.Value = true
else
script.Parent.Text = "Light Mode"
wait (0.1)
Create.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Friends.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Games.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Home.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Settings.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
script.Parent.Parent.Parent.DarkMode.Value = false
end
end)
Made it simpler too. Your if statements are supposed to be inside the event so that they fire every time the UI is clicked. Then you can do an if-else instead of two if statements
You can drop the double equals true when evaluating truthiness; if <value> is equivalent to if <value> == true, and you can similarly use if not <value> to evaluate if something is false.
I noticed you’re running the same operation on multiple instances that share the same parent; instead of repeating the same code, you can use :GetChildren() and loop through the results like so:
for _, element in pairs(script.Parent.Parent.Parent:GetChildren()) do
element.BackgroundColor3 = Color3.fromRGB(6, 5, 34)
end
Hope to see you around more, and good luck!
Edit: You’ll want to move your DarkMode value elsewhere if you use the above loop, as value objects don’t have a BackgroundColor3 property and it will cause an error.