Fake Night System!

Quite simple! How do I make a fake night system? So when it hits night time the sun will go to the position of the moon and then it’ll act like the moon when the fake moon goes down it’ll go back to the original position and you get the idea.

I tried this, but I don’t know how to fix it so it does this. the moon still appears, and since I’m bad with the math.

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

Lighting.Sky.SunAngularSize = 21
Lighting.Sky.MoonAngularSize = 0

local dayLatitude = 67.734
local nightLatitude = -67.734
local clockTime = 6
local incrementSpeed = 0.05

function updateLighting()
    if clockTime >= 18 or clockTime < 6 then
        Lighting.ClockTime = clockTime
        Lighting.GeographicLatitude = nightLatitude
        Lighting.Brightness = 0.5
        Lighting.Ambient = Color3.new(0.1, 0.1, 0.2)
        Lighting.ColorShift_Bottom = Color3.new(0.1, 0.1, 0.3)
        Lighting.ColorShift_Top = Color3.new(0.2, 0.2, 0.4)
    else
        Lighting.ClockTime = clockTime
        Lighting.GeographicLatitude = dayLatitude
        Lighting.Brightness = 2
        Lighting.Ambient = Color3.new(0.7, 0.7, 0.7)
        Lighting.ColorShift_Bottom = Color3.new(1, 1, 1)
        Lighting.ColorShift_Top = Color3.new(1, 1, 1)
    end
end

RunService.Heartbeat:Connect(function(deltaTime)
    clockTime = clockTime + incrementSpeed * deltaTime * 60
    if clockTime >= 24 then
        clockTime = 0
    end
    
    updateLighting()
end)
1 Like

What are you trying to accomplish with this? I thought it might be to get shadows from the moon at night but it seems like Roblox does that automatically.

One problem is that I think the latitude you have might be too high. At 67 the sun doesn’t rise very high above the horizon. At 0 it runs straight overhead. At 33 or so it makes more of a high arc.

I’ve played around with the code some but I’m not sure I’m understanding what your end goal is. The code below runs time backward and forward swapping textures but I can’t get the transition to happen smoothly. Also it seems like the stars disappear when the “moon” is showing.

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

Lighting.Sky.SunAngularSize = 21
Lighting.Sky.MoonAngularSize = 0

local MoonTextureId = Lighting.Sky.MoonTextureId
local SunTextureId = Lighting.Sky.SunTextureId

local dayLatitude = 33
local nightLatitude = 33
local clockTime = 6
local incrementSpeed = 0.05

function updateLighting()
	if clockTime >= 18 or clockTime < 6 then
		Lighting.ClockTime = (12 - clockTime) % 24
		Lighting.GeographicLatitude = nightLatitude
		Lighting.Brightness = 0.3
		Lighting.Ambient = Color3.new(0.1, 0.1, 0.2)
		Lighting.ColorShift_Bottom = Color3.new(0.1, 0.1, 0.3)
		Lighting.ColorShift_Top = Color3.new(0.2, 0.2, 0.4)
		Lighting.Sky.SunTextureId = MoonTextureId
	else
		Lighting.ClockTime = clockTime
		Lighting.GeographicLatitude = dayLatitude
		Lighting.Brightness = 2
		Lighting.Ambient = Color3.new(0.7, 0.7, 0.7)
		Lighting.ColorShift_Bottom = Color3.new(1, 1, 1)
		Lighting.ColorShift_Top = Color3.new(1, 1, 1)
		Lighting.Sky.SunTextureId = SunTextureId
	end
end

RunService.Heartbeat:Connect(function(deltaTime)
	clockTime = clockTime + incrementSpeed * deltaTime * 60
	if clockTime >= 24 then
		clockTime = 0
	end

	updateLighting()
	
	print(clockTime,Lighting.ClockTime)
	
end)
1 Like

Yep! That helps thankss! Basically to explain, I’m trying to make it so when its midnight, it’ll switch the suns position to the other sidew basically what this script is doing, so I can make a fake night script with a custom sky box and stuff, thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.