How do i make it bright as if it is day even while it is night?

I have a lighting script that positions the sun behind the closest certain part, It works really well but whenever i surpass its Y position, Everything goes dark. I want it to be always bright as if its day, How can i do this?

2 Likes

You can increase the brightness in lighting settings if it passes the Y position! See how that works. Make sure the brightness doesn’t change in lighting when the lighting script is active, one example can be using a loop (while loop) to keep the brightness static whilst lighting is moving.

Sorry for the late reply, I will try it!

Hello! I tried your method, it worked well, but the moon is providing the light instead of the sun which is behind the part. Do you know how to help me with this?

1 Like

Send me a screenshot of what it looks like and I think maybe could be sunrays or something?

Here is the screenshot, As you can see i have an artificial star on the left which has the real sun behind it, While the moon is on the right. But instead of the sun providing light, its the moon.

Ay, I tested myself what this is and it has something to do with the Geographic Latitude where the moon would be there, but it is day time, which is in Lighting.

Again, sorry for the REALLY late reply. Here is the localscript to the lighting script, I’m a beginner developer and don’t know much yet so help would be appreciated!

local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")

local cam = workspace.CurrentCamera

Lighting.ClockTime = 6

local atan2 = math.atan2
local sqrt = math.sqrt
local tau = math.pi * 2

local p = Instance.new("Part")
local lights = {}

for _, obj in pairs(workspace:GetDescendants()) do
	if obj.Name == "SunFire" then
		table.insert(lights, obj.Parent)
		obj.Parent.CastShadow = false
	end
end

RunService.RenderStepped:Connect(function()
	local closest = nil

	for _, lightPart in pairs(lights) do
		local d = (lightPart.Position - cam.CFrame.Position).Magnitude
		if closest == nil or d < closest[2] then
			closest = {lightPart, d}
		end
	end

	if closest then
		closest = closest[1]
		p.CFrame = CFrame.new(closest.Position, cam.CFrame.Position)

		local dir = (closest.Position - cam.CFrame.Position).unit

		local lf = -1
		local lat = atan2(dir.Z, sqrt(dir.X^2 + dir.Y^2))
		local lon = atan2(dir.Y * lf, dir.X * lf)

		local geoLatitude = (lat / tau) * 360 + 23.5
		local clockTime = (lon / tau) * 24 - 6

		Lighting.GeographicLatitude = geoLatitude
		Lighting.ClockTime = clockTime % 24	


		-- Adjust brightness based on distance
		if game.Lighting.ClockTime >= 7 and game.Lighting.ClockTime <= 18 then
			Lighting.Brightness = 5000 / math.sqrt((closest.Position - cam.CFrame.Position).Magnitude)
		elseif game.Lighting.ClockTime <= 7 and game.Lighting.ClockTime >= 18 then
			Lighting.Brightness = 350 / math.sqrt((closest.Position - cam.CFrame.Position).Magnitude)
		end
	end
end)
1 Like

This will make the game always bright no matter day or night.

local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")

local cam = workspace.CurrentCamera

Lighting.ClockTime = 6
Lighting.OutdoorAmbient = Color3.new(1, 1, 1) -- Here is where the game is always be bright no matter if your in the day or night time
Lighting.ExposureCompensation = 1.15

local atan2 = math.atan2
local sqrt = math.sqrt
local tau = math.pi * 2

local p = Instance.new("Part")
local lights = {}

for _, obj in pairs(workspace:GetDescendants()) do
	if obj.Name == "SunFire" then
		table.insert(lights, obj.Parent)
		obj.Parent.CastShadow = false
	end
end

RunService.RenderStepped:Connect(function()
	local closest = nil

	for _, lightPart in pairs(lights) do
		local d = (lightPart.Position - cam.CFrame.Position).Magnitude
		if closest == nil or d < closest[2] then
			closest = {lightPart, d}
		end
	end

	if closest then
		closest = closest[1]
		p.CFrame = CFrame.new(closest.Position, cam.CFrame.Position)

		local dir = (closest.Position - cam.CFrame.Position).unit

		local lf = -1
		local lat = atan2(dir.Z, sqrt(dir.X^2 + dir.Y^2))
		local lon = atan2(dir.Y * lf, dir.X * lf)

		local geoLatitude = (lat / tau) * 360 + 23.5
		local clockTime = (lon / tau) * 24 - 6

		Lighting.GeographicLatitude = geoLatitude
		Lighting.ClockTime = clockTime % 24	


		-- Adjust brightness based on distance
		if game.Lighting.ClockTime >= 7 and game.Lighting.ClockTime <= 18 then
			Lighting.Brightness = 5000 / math.sqrt((closest.Position - cam.CFrame.Position).Magnitude)
		elseif game.Lighting.ClockTime <= 7 and game.Lighting.ClockTime >= 18 then
			Lighting.Brightness = 350 / math.sqrt((closest.Position - cam.CFrame.Position).Magnitude)
		end
	end
end)

Hi, thank you for the reply and sorry for late reply since we have different timezones aswell.

It works well but i didn’t get the results i liked. The moon is providing the light instead of the sun, Is there anyway to position the moon behind the artificial star instead of the sun? It’s also too bright.

Help would be appreciated!

1 Like

See about this?

local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")

local cam = workspace.CurrentCamera

Lighting.ClockTime = 6
Lighting.OutdoorAmbient = Color3.new(0.588235, 0.588235, 0.588235) -- Here is where the game is always be bright no matter if your in the day or night time
Lighting.ExposureCompensation = 0.88
Lighting.Sky.MoonAngularSize = 0
Lighting.Brightness = 2.8

local atan2 = math.atan2
local sqrt = math.sqrt
local tau = math.pi * 2

local p = Instance.new("Part")
local lights = {}

for _, obj in pairs(workspace:GetDescendants()) do
	if obj.Name == "SunFire" then
		table.insert(lights, obj.Parent)
		obj.Parent.CastShadow = false
	end
end

RunService.RenderStepped:Connect(function()
	local closest = nil

	for _, lightPart in pairs(lights) do
		local d = (lightPart.Position - cam.CFrame.Position).Magnitude
		if closest == nil or d < closest[2] then
			closest = {lightPart, d}
		end
	end

	if closest then
		closest = closest[1]
		p.CFrame = CFrame.new(closest.Position, cam.CFrame.Position)

		local dir = (closest.Position - cam.CFrame.Position).unit

		local lf = -1
		local lat = atan2(dir.Z, sqrt(dir.X^2 + dir.Y^2))
		local lon = atan2(dir.Y * lf, dir.X * lf)

		local geoLatitude = (lat / tau) * 360 + 23.5
		local clockTime = (lon / tau) * 24 - 6

		Lighting.GeographicLatitude = geoLatitude
		Lighting.ClockTime = clockTime % 24	


		-- Adjust brightness based on distance
		if game.Lighting.ClockTime >= 7 and game.Lighting.ClockTime <= 18 then
			Lighting.Brightness = 5000 / math.sqrt((closest.Position - cam.CFrame.Position).Magnitude)
			Lighting.Sky.MoonAngularSize = 9 -- Controls the size
			Lighting.Brightness = 0.77
			Lighting.OutdoorAmbient = Color3.fromRGB(0, 0, 0)
		elseif game.Lighting.ClockTime <= 7 and game.Lighting.ClockTime >= 18 then
			Lighting.Brightness = 350 / math.sqrt((closest.Position - cam.CFrame.Position).Magnitude)
			Lighting.Sky.MoonAngularSize = 0 -- Leave this like this as this happens when the sun rises
			Lighting.OutdoorAmbient = Color3.fromRGB(255, 255, 255)
		end
	end
end)

is controlling the moon and sun size really mandatory??

I tested it and it didn’t work at all.

Are you using AI to code that for you? There are some really redundant lines of code in it.
Changing the size of the sun and moon is redundant, they won’t appear anyway.
Also changing the ambient is useless too, Not jumping to conclusions right away though.

My bad about the change in sizes, I’ll test to see if I can position the moon behind it and I’ll reduce the brightness. No AI, but was testing around with the code.

I don’t think I know how to position the moon behind the sun, but did some final code here and see if that works out. I turned down the brightness too.

local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")

local cam = workspace.CurrentCamera

Lighting.ClockTime = 7
Lighting.OutdoorAmbient = Color3.new(1, 1, 1) -- Here is where the game is always be bright no matter if your in the day or night time
Lighting.ExposureCompensation = -2.08 -- Can control the brightness
-- I would also control the brightness in Lighting if you think that's not enough

local atan2 = math.atan2
local sqrt = math.sqrt
local tau = math.pi * 2

local p = Instance.new("Part")
local lights = {}

for _, obj in pairs(workspace:GetDescendants()) do
	if obj.Name == "SunFire" then
		table.insert(lights, obj.Parent)
		obj.Parent.CastShadow = false
	end
end

RunService.RenderStepped:Connect(function()
	local closest = nil

	for _, lightPart in pairs(lights) do
		local d = (lightPart.Position - cam.CFrame.Position).Magnitude
		if closest == nil or d < closest[2] then
			closest = {lightPart, d}
		end
	end

	if closest then
		closest = closest[1]
		p.CFrame = CFrame.new(closest.Position, cam.CFrame.Position)

		local dir = (closest.Position - cam.CFrame.Position).unit

		local lf = -1
		local lat = atan2(dir.Z, sqrt(dir.X^2 + dir.Y^2))
		local lon = atan2(dir.Y * lf, dir.X * lf)

		local geoLatitude = (lat / tau) * 360 + 23.5
		local clockTime = (lon / tau) * 24 - 6

		Lighting.GeographicLatitude = geoLatitude
		Lighting.ClockTime = clockTime % 24	


		-- Adjust brightness based on distance
		if game.Lighting.ClockTime >= 7 and game.Lighting.ClockTime <= 18 then -- Day
			Lighting.Brightness = 5000 / math.sqrt((closest.Position - cam.CFrame.Position).Magnitude)
			Lighting.Sky.CelestialBodiesShown = true  -- Bring up the default moon and sun
		elseif game.Lighting.ClockTime <= 7 and game.Lighting.ClockTime >= 18 then -- Night
			Lighting.Brightness = 350 / math.sqrt((closest.Position - cam.CFrame.Position).Magnitude)
			Lighting.Sky.CelestialBodiesShown = false  -- Hide the default moon and sun
		end
	end
end)
1 Like

It works really well! Sorry for the late reply though.

1 Like

Oh thanks man! It’s alright with the timing. Sometimes that’s the case and I’m in UK :+1: