I need help with shortening/simplifying this code

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to shorten my 105 Line code

  2. What is the issue? The code is way to long that it goes off screen

  3. **What solutions have you tried so far? None

Hello, so I made a very realistic daylight cycle that messes with the lighting but the problem is it i way way way to long if some could shorten this help would be much helpful.

Very long script

local lighting = game.Lighting
local Brightness = game.Lighting.Brightness
local ShadowSoftness = game.Lighting.ShadowSoftness
local GlobalShadows = game.Lighting.GlobalShadows
local Ambident = game.Lighting.Ambient
local Outdoors = game.Lighting.OutdoorAmbient
local FogStart = game.Lighting.FogStart
local FogEnd = game.lighting.FogEnd
local fogcolor = game.Lighting.FogColor
while true do
	wait(1)
	if game.Lighting.ClockTime >=17.7 then
		game.Lighting.GlobalShadows = true
		game.Lighting.OutdoorAmbient = Color3.fromRGB(45,45,45)
		game.Lighting.Ambient = Color3.fromRGB(118,118,118)
		game.Lighting.Brightness = 1
		game.Lighting.FogStart = false
		game.Lighting.FogColor = Color3.new()
	else 
		if game.Lighting.ClockTime > 18.01 then
			game.Lighting.GlobalShadows = false
			game.Lighting.OutdoorAmbient = Color3.fromRGB(35,35,35)
			game.Lighting.Ambient = Color3.fromRGB(50,50,50)
			game.Lighting.Brightness = 0
			game.Lighting.FogStart = math.random()
			game.Lighting.FogColor = Color3.new(255,255,255)
		else
			if game.Lighting.ClockTime >= 19.48 then
				game.Lighting.GlobalShadows = false
				game.Lighting.OutdoorAmbient = Color3.fromRGB(30,30,30)
				game.Lighting.Ambient = Color3.fromRGB(25,25,25)
				game.Lighting.Brightness = 0
				game.Lighting.FogStart = math.random()
				game.Lighting.FogColor = Color3.new(255,255,255)
				
			else
				if game.Lighting.ClockTime >= 21 then
					game.Lighting.GlobalShadows = false
					game.Lighting.OutdoorAmbient = Color3.fromRGB(25,25,25)
					game.Lighting.Ambient = Color3.fromRGB(0,0,0)
					game.Lighting.Brightness = 0
					game.Lighting.FogStart = math.random()
					game.Lighting.FogColor = Color3.new(255,255,255)
				else
					if game.Lighting.ClockTime >=4 then
						game.Lighting.GlobalShadows = false
						game.Lighting.OutdoorAmbient = Color3.fromRGB(35,35,35)
						game.Lighting.Ambient = Color3.fromRGB(5,5,5)
						game.Lighting.Brightness = 0
						game.Lighting.FogStart = math.random()
						game.Lighting.FogColor = Color3.new(255,255,255)
					else 
						if game.Lighting.ClockTime >= 6.07 then
							game.Lighting.GlobalShadows = false
							game.Lighting.OutdoorAmbient = Color3.fromRGB(40,40,40)
							game.Lighting.Ambient = Color3.fromRGB(10,10,10)
							game.Lighting.Brightness = 1
							game.Lighting.FogStart = false
							game.Lighting.FogColor = Color3.new(255,255,255)
						else 
							 if game.Lighting.ClockTime >= 6.3 then
								game.Lighting.GlobalShadows = false
								game.Lighting.OutdoorAmbient = Color3.fromRGB(45,45,45)
								game.Lighting.Ambient = Color3.fromRGB(15,15,15)
								game.Lighting.Brightness = 1
								game.Lighting.FogStart = false
								game.Lighting.FogColor = Color3.new(255,255,255)
							else
								if game.Lighting.ClockTime >= 9 then
									game.Lighting.GlobalShadows = false
									game.Lighting.OutdoorAmbient = Color3.fromRGB(65,65,65)
									game.Lighting.Ambient = Color3.fromRGB(148,148,148)
									game.Lighting.Brightness = 2
									game.Lighting.FogStart = false
									game.Lighting.FogColor = Color3.new(255,255,255)
								else
									if game.Lighting.ClockTime >=12 then
										game.Lighting.GlobalShadows = true
										game.Lighting.OutdoorAmbient = Color3.fromRGB(70,70,70)
										game.Lighting.Ambient = Color3.fromRGB(155,155,155)
										game.Lighting.Brightness = 2
										game.Lighting.FogStart = false
										game.Lighting.FogColor = Color3.new(255,255,255)
									else 
										if game.Lighting.ClockTime >= 15 then
											game.Lighting.GlobalShadows = true
											game.Lighting.OutdoorAmbient = Color3.fromRGB(80,80,80)
											game.Lighting.Ambient = Color3.fromRGB(165,165,165)
											game.Lighting.Brightness = 3
											game.Lighting.FogStart = false
											game.Lighting.FogColor = Color3.new(255,255,255)
										end
									end
								end
							end
						end
				end
				
			end
		end
	end
			
		end
	end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

For starters learn how to use

if... then
   ....
elseif... then
   ....
end

First of all.

Why are you defining all of these variables if you are not going to use them on your code?

Second, ‘elseif’ is a thing on roblox, you can delete mostly every ‘end’ you are using on your script by changing this:

else 
	if game.Lighting.ClockTime > 18.01 then
             ...
        end
end

into this:

elseif game.Lighting.ClockTime > 18.01 then
        ...
end
2 Likes