Day/Night Cycle script not working

I just made this night/day cycle script and it’s not working. Did I use tables wrong or?
Also, it doesn’t print any errors.

Code:

--// Locals

local TS = game:GetService("TweenService")
local Lighting = game.Lighting


--// Settings

local daySettings = {
	
	["Ambience"] = Color3.fromRGB(91,91,91);
	["Brightness"] = 2
	
};

local nightSettings = {

	["Ambience"] = Color3.fromRGB(0,0,0);
	["Brightness"] = 0

};

local dayTime = 15
local nightTime = 10


--// Functions

function setDay()
	TS:Create(Lighting.Ambient,TweenInfo.new(4),{Color3 = daySettings.Ambience}):Play()
	TS:Create(Lighting,TweenInfo.new(4),{Brightness = daySettings.Brightness}):Play()
	Lighting.NightSky.Parent = game.ReplicatedStorage
	game.ReplicatedStorage.DaySky.Parent = Lighting
end

function setNight()
	TS:Create(Lighting.Ambient,TweenInfo.new(4),{Color3 = nightSettings.Ambience}):Play()
	TS:Create(Lighting,TweenInfo.new(4),{Brightness = nightSettings.Brightness}):Play()
	Lighting.DaySky.Parent = game.ReplicatedStorage
	game.ReplicatedStorage.NightSky.Parent = Lighting
end


--// Code

while true do
	wait(dayTime--[[*60]])
	setNight()
	wait(nightTime--[[*60]])
	setDay()
end

Any help is apprectiated.

I personaly use this :

--Variable--

local MinutesAfterMidnight = 60*12

--Variable--

--Time--

while true do
	game.Lighting:SetMinutesAfterMidnight(MinutesAfterMidnight)
	MinutesAfterMidnight = MinutesAfterMidnight + 1/60
	wait(1)
end

--Time--

I hope that was helpful ! :grinning:
EDIT : I use roblox sky ! :neutral_face:

Yeah I would normally use it, but I can’t as my game doesn’t use “that” lighting.

1 Like

Maybe you can do that :

--// Locals

local TS = game:GetService("TweenService")
local Lighting = game.Lighting


--// Settings

local daySettings = {
	
	["Ambience"] = Color3.fromRGB(91,91,91);
	["Brightness"] = 2
	
};

local nightSettings = {

	["Ambience"] = Color3.fromRGB(0,0,0);
	["Brightness"] = 0

};

--// Functions

function setDay()
	TS:Create(Lighting.Ambient,TweenInfo.new(4),{Color3 = daySettings.Ambience}):Play()
	TS:Create(Lighting,TweenInfo.new(4),{Brightness = daySettings.Brightness}):Play()
	Lighting.NightSky.Parent = game.ReplicatedStorage
	game.ReplicatedStorage.DaySky.Parent = Lighting
end

function setNight()
	TS:Create(Lighting.Ambient,TweenInfo.new(4),{Color3 = nightSettings.Ambience}):Play()
	TS:Create(Lighting,TweenInfo.new(4),{Brightness = nightSettings.Brightness}):Play()
	Lighting.DaySky.Parent = game.ReplicatedStorage
	game.ReplicatedStorage.NightSky.Parent = Lighting
end


--// Code

local TimeOfDay = game.Lighting.TimeOfDay

spawn(function()
 while wait() do
	 if TimeOfDay == "15:00:00" then
      setDay()
     elseif TimeOfDay == "10:00:00" then
      setNight()
   end
end)

spawn(function()
   while wait() do
   TimeOfDay = game.Lighting.TimeOfDay
   end
end)

weres located the script???

Its in ServerScriptService. (Server script ofc)

Try this:

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")

--//Controls
local dayTime = 15
local nightTime = 10

--//Tables
local daySettings = {
	Ambience = Color3.fromRGB(91, 91, 91),
	Brightness = 2
}

local nightSettings = {
	Ambience = Color3.fromRGB(0, 0, 0),
	Brightness = 0
}

--//Functions
function setDay()
	TweenService:Create(Lighting.Ambient, TweenInfo.new(4), {Color3 = daySettings.Ambience}):Play()
	TweenService:Create(Lighting, TweenInfo.new(4), {Brightness = daySettings.Brightness}):Play()
	
	Lighting.NightSky.Parent = ReplicatedStorage
	ReplicatedStorage.DaySky.Parent = Lighting
end

function setNight()
	TweenService:Create(Lighting.Ambient, TweenInfo.new(4), {Color3 = nightSettings.Ambience}):Play()
	TweenService:Create(Lighting, TweenInfo.new(4), {Brightness = nightSettings.Brightness}):Play()
	
	Lighting.DaySky.Parent = ReplicatedStorage
	ReplicatedStorage.NightSky.Parent = Lighting
end

--//Loops
while task.wait(dayTime --[[*60]]) do
	setNight()
	
	task.wait(nightTime--[[*60]])
	setDay()
end