Day & Night Cycle - Preview
INFORMATION
-
Lighting tweens locally
-
TweenService used for maximum smoothness & diverse styles
-
Configurable : EasingStyle, EasingDirection, time_Interval, time_Increment
-
Global Time - everyone shares the same time regardless of when they join
-
TweenInfo changable in run time
Limitations ( Network & Device )
-
TweenService tweens from any higher number than 0 to 0, reversing time, thus time will be set to 0 if the Tween fails to reach 24.
-
Replication from Server to Client is not real time. To combat this, prior tweens created will pause and be dismissed, playing the newer one.
Documentation
Module_Time:start_Time()
Documentation : start_Time
Information
- Starts
Day Night Cycle
.
Example
local Module_Time = require(script:WaitForChild("Module_Time")) -- Location of "Module_Time"
Module_Time:start_Time()
Module_Time.time_Wait
( REPLICATES )
Documentation : time_Wait
Information
-
Determines the time the loop pauses before running again.
-
Expects a number.
Example
Module_Time.time_Wait = .25 --Now the loop waits .25 seconds before updating time.
Module_Time.time_Increment
( REPLICATES )
Documentation : time_Increment
Information
- Determines the hours advanced per ran loop.
- Expects a number.
Example
Module_Time.time_Increment = 1 --Now the time increments by 1 hour every time the loop runs
Module_Time.tween_EasingStyle
( REPLICATES )
Documentation : tween_EasingStyle
Information
-
Determines the time the EasingStyle used in the tween.
-
Expects a string (name of the easing style)
Example
Module_Time.tween_EasingStyle = "Linear" --Replicates, Clients will now use style.
Module_Time.tween_EasingDirection
( REPLICATES )
Documentation : tween_EasingDirection
Information
-
Determines the time the EasingDirection used in the tween.
-
Expects a string (name of the easing direction)
Example
Module_Time.tween_EasingDirection = "In" --Replicates, Clients will now use direction.
Love it? Use it.
-
Day Night cycle.rbxm
(2.4 KB)
-
Source code ( Below )
Local Script OR Script with RunContext as Client
local tween_Current = nil
local Service_TweenService = game:GetService("TweenService")
local Service_Lighing = game:GetService("Lighting")
local tween_Info = TweenInfo.new(Service_Lighing:GetAttribute("time_Wait"),Enum.EasingStyle[Service_Lighing:GetAttribute("tween_EasingStyle")],Enum.EasingDirection[Service_Lighing:GetAttribute("tween_EasingDirection")],0,false,0)
Service_Lighing.ClockTime = Service_Lighing:GetAttribute("Time")
Service_Lighing:GetAttributeChangedSignal("Time"):Connect(function()
if tween_Current and tween_Current.PlaybackState == Enum.PlaybackState.Playing then
tween_Current:Pause()
--print("Paused Prior Track")
end
if Service_Lighing.ClockTime > Service_Lighing:GetAttribute("Time") then
Service_Lighing.ClockTime = 0
-- print("Patched : Time = 0")
else
tween_Current = Service_TweenService:Create(Service_Lighing,tween_Info,{ClockTime = Service_Lighing:GetAttribute("Time")})
tween_Current:Play()
end
--print(Service_Lighing:GetAttribute("Time"))
end)
Service_Lighing:GetAttributeChangedSignal("time_Wait") do
tween_Info = TweenInfo.new(Service_Lighing:GetAttribute("time_Wait"),tween_Info.EasingStyle,tween_Info.EasingDirection,0,false,0)
end
Service_Lighing:GetAttributeChangedSignal("tween_EasingStyle") do
tween_Info = TweenInfo.new(tween_Info.Time,Enum.EasingStyle[Service_Lighing:GetAttribute("tween_EasingStyle")],tween_Info.EasingDirection,0,false,0)
end
Service_Lighing:GetAttributeChangedSignal("tween_EasingDirection") do
tween_Info = TweenInfo.new(tween_Info.Time,tween_Info.EasingStyle,Enum.EasingDirection[Service_Lighing:GetAttribute("tween_EasingDirection")],0,false,0)
end
Module Script
return {
time_Wait = .25,
time_Increment = 1,
tween_EasingStyle = "Linear",
tween_EasingDirection = "Out",
start_Time = function(self)
if not game.Lighting:GetAttribute("Time") then game.Lighting:SetAttribute("Time",0) end
if not game.Lighting:GetAttribute("time_Wait") then game.Lighting:SetAttribute("time_Wait",self.time_Wait) end
if not game.Lighting:GetAttribute("time_Increment") then game.Lighting:SetAttribute("time_Increment",self.time_Increment) end
if not game.Lighting:GetAttribute("tween_EasingStyle") then game.Lighting:SetAttribute("tween_EasingStyle",self.tween_EasingStyle) end
if not game.Lighting:GetAttribute("tween_EasingDirection") then game.Lighting:SetAttribute("tween_EasingDirection",self.tween_EasingDirection) end
while task.wait(self.time_Wait) do
if game.Lighting:GetAttribute("Time") + self.time_Increment <= 24 then
game.Lighting:SetAttribute("Time",game.Lighting:GetAttribute("Time") + self.time_Increment)
else
game.Lighting:SetAttribute("Time",self.time_Increment)
end
end
end,
}
Script with RunContext Legacy OR Server
local Module_Time = require(script:WaitForChild("Module_Time"))
Module_Time:start_Time()