This repository was archived by the owner on May 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleScript.lua
More file actions
1051 lines (899 loc) · 38.5 KB
/
ModuleScript.lua
File metadata and controls
1051 lines (899 loc) · 38.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
___________________________________________________________________________________________________________________
!!!!! Important !!!!!
_____________________
Don't forget to require this module when attempting to use it! The easiest way is just something like:
local DynamicLightingModule = require(game:GetService("ServerScriptService"):WaitForChild("DynamicLightingModule"))
at the start of your script
___________________________________________________________________________________________________________________
When calling the DynamicLightingSystem from another script and starting it, you can do so like:
local DynamicLightingSystem = coroutine.create(DynamicLightingModule.DynamicLightingSystem)
coroutine.resume(DynamicLightingSystem, 1)
or
DynamicLightingModule.DynamicLightingSystem()
or
DynamicLightingModule.DynamicLightingSystem(1)
*The 1 you see above is an optional wait period that you can include that directs how often the module checks for Lighting Period changes
___________________________________________________________________________________________________________________
Enjoy and please let me know if there are any bugs!!
-https_KingPie
--]]
local module = {}
--// Services
local Lighting = game:GetService("Lighting")
local TweenService = game:GetService("TweenService")
local Workspace = game:GetService("Workspace")
--// Primary Variables
local LightingSettings = { --// Add as many or as little Lighting Periods as you like, just make sure they are continuous i.e. (0 - 3, 3-12, 12-20, 20-0) don't leave gaps like (0-3, 6-12, 12-20, 20-0)
["LightingPeriodName1"] = {
TimeStart = 5,
TimeEnd = 6.3,
Ambient = Color3.fromRGB(115, 78, 0),
OutdoorAmbient = Color3.fromRGB(128, 124, 81),
ShadowSoftness = 0.4,
LightsOn = false,
},
["LightingPeriodName2"] = {
TimeStart = 6.3,
TimeEnd = 17.3,
Ambient = Color3.fromRGB(136, 95, 0),
OutdoorAmbient = Color3.fromRGB(128, 128, 128),
ShadowSoftness = 0.65,
LightsOn = false,
},
["LightingPeriodName3"] = {
TimeStart = 17.3,
TimeEnd = 18.5,
Ambient = Color3.fromRGB(115, 78, 0),
OutdoorAmbient = Color3.fromRGB(128, 109, 86),
ShadowSoftness = 0.3,
LightsOn = false,
},
["LightingPeriodName4"] = {
TimeStart = 18.5,
TimeEnd = 5,
Ambient = Color3.fromRGB(104, 67, 0),
OutdoorAmbient = Color3.fromRGB(95, 100, 128),
ShadowSoftness = 0.1,
LightsOn = true,
},
}
local WeatherSettings = {
["None"] = { --// This is your default settings (do not delete this table) [some very generic default settings have been loaded in - feel free to change]
BlurSize = 0,
SunRaysIntensity = .25,
FogColor = Color3.fromRGB(191, 191, 191),
FogEnd = 5000,
Brightness = 1,
--// No Ambient, OutdoorAmbient, or ShadowSoftness settings as this will be replaced by whatever settings are applied based on Lighting Period
WaterReflectance = 1,
WaterWaveSize = 0.35,
WaterWaveSpeed = 9.77,
LightsOn = false,
},
["NameThisWhateverYouWant"] = {
BlurSize = 0,
SunRaysIntensity = 0,
FogColor = Color3.fromRGB(0,0,0),
FogEnd = 10000,
Brightness = 0,
Ambient = Color3.fromRGB(0, 0, 0),
OutdoorAmbient = Color3.fromRGB(0,0,0),
ShadowSoftness = 0,
WaterReflectance = 0,
WaterWaveSize = 0,
WaterWaveSpeed = 0,
LightsOn = true,
},
}
local ChangingLights = {
["Parts"] = {
["NameThisWhateverYouWant"] = {
InstanceName = "",
UnlitColor = Color3.fromRGB(231, 231, 236),
UnlitMaterial = Enum.Material.Glass,
LitColor = Color3.fromRGB(218, 133, 65),
LitMaterial = Enum.Material.Neon,
ChanceOfIllumination = 80, --// Enter without percent sign (ex: 33% = 33)
},
["NameThisWhateverYouWant2"] = {
InstanceName = "", --This is the only one appearing
UnlitColor = Color3.fromRGB(0, 0, 0),
UnlitMaterial = Enum.Material.Glass,
LitColor = Color3.fromRGB(0, 0, 0),
LitMaterial = Enum.Material.Neon,
ChanceOfIllumination = 80, --// Enter without percent sign (ex: 33% = 33)
},
--// Feel free to add more!
},
["Lights"] = {
["NameThisWhateverYouWant"] = {
InstanceName = "",
LitBrightness = 1,
UnlitBrightness = 0,
ChanceOfIllumination = 80, --// Enter without percent sign (ex: 33% = 33)
},
["NameThisWhateverYouWant2"] = {
InstanceName = "",
LitBrightness = 1,
UnlitBrightness = 0,
ChanceOfIllumination = 80, --// Enter without percent sign (ex: 33% = 33)
},
--// Feel free to add more!
},
["MultiInstanceLights"] = { --//Only use if utilizing randomization feature (unless you really want to, I can't stop you and it's not actually that big of a deal)
["NameThisWhateverYouWant"] = {
ReferencePartName = "",
ReferencePartType = "Part", --// Either Light or Part. Leave as nil if you want zero changes on the reference part
--// Only relevant if ReferencePartType is "Light"
LitBrightness = 1,
UnlitBrightness = 0,
--// Only relevant if ReferencePartType is "Part"
UnlitColor = Color3.fromRGB(231, 231, 236),
UnlitMaterial = Enum.Material.Glass,
LitColor = Color3.fromRGB(218, 133, 65),
LitMaterial = Enum.Material.Neon,
ChanceOfIllumination = 80,
RelatedParts = {
{
RelatedName = "", --// If set to nil will just reference the parent without checking the parent's name. The name must be specified if the relation is a child because ROBLOX ugh
RelationType = "Child", --// Child or Parent
InstanceType = "Light", --// Light or Part
--// Only relevant if InstanceType is "Light"
LitBrightness = 1,
UnlitBrightness = 0,
--// Only relevant if InstanceType is "Part"
UnlitColor = Color3.fromRGB(0, 0, 0),
UnlitMaterial = Enum.Material.Glass,
LitColor = Color3.fromRGB(0, 0, 0),
LitMaterial = Enum.Material.Neon,
}
},
},
["NameThisWhateverYouWant2"] = {
ReferencePartName = "",
ReferencePartType = "Part", --// Either Light or Part. Leave as nil if you want zero changes on the reference part
--// Only relevant if ReferencePartType is "Light"
LitBrightness = 1,
UnlitBrightness = 0,
--// Only relevant if ReferencePartType is "Part"
UnlitColor = Color3.fromRGB(0, 0, 0),
UnlitMaterial = Enum.Material.Glass,
LitColor = Color3.fromRGB(0, 0, 0),
LitMaterial = Enum.Material.Neon,
ChanceOfIllumination = 80,
RelatedParts = {
{
RelatedName = "", --// If set to nil will just reference the parent without checking the parent's name. The name must be specified if the relation is a child because ROBLOX ugh
RelationType = "Child", --// Child or Parent
InstanceType = "Light", --// Light or Part
--// Only relevant if InstanceType is "Light"
LitBrightness = 1,
UnlitBrightness = 0,
--// Only relevant if InstanceType is "Part"
UnlitColor = Color3.fromRGB(0, 0, 0),
UnlitMaterial = Enum.Material.Glass,
LitColor = Color3.fromRGB(0, 0, 0),
LitMaterial = Enum.Material.Neon,
}
},
},
--// Feel free to add more!
}
}
--// Secondary Varaibles
local Weather = false --// Indicates non-clear or non-snow weather
local LightsActive = false --// Defaults to off, adjust if necessary
local TimeAdjusted = false --// Indicated whether TimeAdjusted zones have been set up
local CurrentLightingPeriod --// Held primarily to see if a tween change is necessary
local LightingTweenInformation = TweenInfo.new(
20,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local WeatherTweenInformation = TweenInfo.new(
10,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
--// Core Function
function module.DynamicLightingSystem(WaitTime) --// This can be the sole thing called and this will properly set up and run the Dynamic Lighting system as a coroutine
if WaitTime == nil then
WaitTime = 1 --// Default value
end
CurrentLightingPeriod = module.GetLightingPeriod() --// Records the current Lighting Period
if Weather == false then
module.SetLighting(CurrentLightingPeriod) --// Activates the lighting settings for the current Lighting Period if there is no weather
module.HandleLightsLightingPeriod(CurrentLightingPeriod, "Set") --Handles whether lights need to be turned on for the current Lighting Period
end
local SetUpAdjustedStart = coroutine.create(module.AdjustedStart)
coroutine.resume(SetUpAdjustedStart) --// Sets up the adjusted start ranges
if Lighting:FindFirstChildWhichIsA("SunRaysEffect") == nil then --// Creates a Sun Rays effect if necessary
local SunRays = Instance.new("SunRaysEffect")
SunRays.Parent = Lighting
end
if Lighting:FindFirstChildWhichIsA("BlurEffect") == nil then --// Creates a Blur effect fi necessary
local Blur = Instance.new("BlurEffect")
Blur.Parent = Lighting
Blur.Size = 0
end
while wait(WaitTime) do
if TimeAdjusted == true then
if Weather == false then
if CurrentLightingPeriod ~= module.CheckForPeriodChange() then --// Checks for impending Lighting Period changes
module.TweenLightingSettings(module.CheckForPeriodChange()) --// Starts tweening light settings when a LightingPeriod change is detected
end
end
else
--// This just means it is waiting on the Adjusted Start ranges to configure
end
end
end
--// Get Functions
function module.GetLightingSettings() --// Gets the LightingSettings table
return LightingSettings
end
function module.GetWeatherSettings() --// Gets the WeatherSettings table
return WeatherSettings
end
function module.GetLightingPeriod() --// Gets the index name of the current LightingPeriod that the ClockTime is within
local CurrentTime = Lighting.ClockTime
for LightingPeriod, PeriodSettings in pairs(LightingSettings) do
if PeriodSettings.TimeStart < PeriodSettings.TimeEnd then --// Expected (ex: starts at 5 ends at 13)
if CurrentTime >= PeriodSettings.TimeStart and CurrentTime < PeriodSettings.TimeEnd then
return LightingPeriod
end
else --// Slightly abnormal cases where times go over midnight (ex: starts at 22 ends at 4)
if (CurrentTime >= PeriodSettings.TimeStart and CurrentTime < 24) or CurrentTime < PeriodSettings.TimeEnd then
return LightingPeriod
end
end
end
warn("Error: Current ClockTime ".. CurrentTime.. " is not within a specified Time Period")
end
--// (Pretty much the same code as above, but this checks with the AdjustedStart)
function module.CheckForPeriodChange() --// Gets the index of whatever adjustment period the current ClockTime falls within
local CurrentTime = Lighting.ClockTime
for LightingPeriod, PeriodSettings in pairs(LightingSettings) do
if PeriodSettings.AdjustedStart < PeriodSettings.AdjustedEnd then --// Expected (ex: starts at 5 ends at 13)
if CurrentTime >= PeriodSettings.AdjustedStart and CurrentTime < PeriodSettings.AdjustedEnd then
return LightingPeriod
end
else --// Slightly abnormal cases where times go over midnight (ex: starts at 22 ends at 4)
if (CurrentTime >= PeriodSettings.AdjustedStart and CurrentTime < 24) or CurrentTime < PeriodSettings.AdjustedEnd then
return LightingPeriod
end
end
end
warn("Ensure all time periods are continuous, a gap has been detected at time ".. CurrentTime)
end
--//Set Functions
function module.SetWeather(WeatherType) --// Immediately applies the lighting settings for a weather period
local SpecifiedWeatherSettings = WeatherSettings[WeatherType]
if WeatherType ~= "None" then
if SpecifiedWeatherSettings ~= nil then
Lighting.FogEnd = SpecifiedWeatherSettings.FogEnd
Lighting.FogEnd = SpecifiedWeatherSettings.FogEnd
Lighting.FogColor = SpecifiedWeatherSettings.FogColor
Lighting.Ambient = SpecifiedWeatherSettings.Ambient
Lighting.OutdoorAmbient = SpecifiedWeatherSettings.OutdoorAmbient
Lighting.Brightness = SpecifiedWeatherSettings.Brightness
Lighting.ShadowSoftness = SpecifiedWeatherSettings.ShadowSoftness
local SunRaysEffect = Lighting:FindFirstChildWhichIsA("SunRaysEffect")
SunRaysEffect.Intensity = SpecifiedWeatherSettings.SunRaysIntensity
local BlurEffect = Lighting:FindFirstChildWhichIsA("BlurEffect")
BlurEffect.Size = SpecifiedWeatherSettings.BlurSize
local Terrain = Workspace.Terrain
Terrain.WaterReflectance = SpecifiedWeatherSettings.WaterReflectance
Terrain.WaterWaveSize = SpecifiedWeatherSettings.WaterWaveSize
Terrain.WaterWaveSpeed = SpecifiedWeatherSettings.WaterWaveSpeed
module.HandleLightsWeather(WeatherType, "Set")
Weather = true
else
warn("Weather input ".."//"..WeatherType.."//".." is not in the WeatherSettings")
end
else
Weather = false
Lighting.FogEnd = SpecifiedWeatherSettings.FogEnd
Lighting.FogEnd = SpecifiedWeatherSettings.FogEnd
Lighting.FogColor = SpecifiedWeatherSettings.FogColor
Lighting.Brightness = SpecifiedWeatherSettings.Brightness
--// Ambient, OutdoorAmbient, and ShadowSoftness are taken care of by the Lighting Period
local SunRaysEffect = Lighting:FindFirstChildWhichIsA("SunRaysEffect")
SunRaysEffect.Intensity = SpecifiedWeatherSettings.SunRaysIntensity
local BlurEffect = Lighting:FindFirstChildWhichIsA("BlurEffect")
BlurEffect.Size = SpecifiedWeatherSettings.BlurSize
local Terrain = Workspace.Terrain
Terrain.WaterReflectance = SpecifiedWeatherSettings.WaterReflectance
Terrain.WaterWaveSize = SpecifiedWeatherSettings.WaterWaveSize
Terrain.WaterWaveSpeed = SpecifiedWeatherSettings.WaterWaveSpeed
local LightingPeriod = module.GetLightingPeriod()
module.SetLighting(LightingPeriod)
module.HandleLightsLightingPeriod(LightingPeriod, "Set")
end
end
function module.SetLighting(LightingPeriod) --// Immediately applies the light settings for the current lighting period
Lighting.Ambient = LightingSettings[LightingPeriod].Ambient
Lighting.OutdoorAmbient = LightingSettings[LightingPeriod].OutdoorAmbient
Lighting.ShadowSoftness = LightingSettings[LightingPeriod].ShadowSoftness
end
--// Handling Functions
function module.HandleLightsLightingPeriod(LightingPeriod, Type) --// Handles turning on/off lights for the Lighting Periods
if LightsActive ~= LightingSettings[LightingPeriod].LightsOn then --// Lights must be either turned on or off
local ActivateLights
if LightsActive == false and LightingSettings[LightingPeriod].LightsOn == true then
ActivateLights = true
LightsActive = true
end
if LightsActive == true and LightingSettings[LightingPeriod].LightsOn == false then
ActivateLights = false
LightsActive = false
end
if Type == "Set" then
module.SetLights(ActivateLights)
elseif Type == "Tween" then
module.TweenLights(ActivateLights)
else
module.TweenLights(ActivateLights)
warn("Type not specified in light handling, assuming Tween")
end
end
end
function module.HandleLightsWeather(WeatherType, Type) --// Handles turning on/off lights for Weather periods
if WeatherType ~= "None" then
if LightsActive ~= WeatherSettings[WeatherType].LightsOn then --// Lights must be either turned on or off
local ActivateLights
if LightsActive == false and WeatherSettings[WeatherType].LightsOn == true then
ActivateLights = true
LightsActive = true
end
if LightsActive == true and WeatherSettings[WeatherType].LightsOn == false then
ActivateLights = false
LightsActive = false
end
if Type == "Set" then
module.SetLights(ActivateLights)
elseif Type == "Tween" then
module.TweenLights(ActivateLights)
else
module.TweenLights(ActivateLights)
warn("Type not specified in light handling, assuming Tween")
end
end
end
end
--// Tween Functions
function module.TweenLightingSettings(LightingPeriod) --// Tweens the lighting settings to the designated Lighting Period
local Tween = TweenService:Create(Lighting, LightingTweenInformation, {Ambient = LightingSettings[LightingPeriod].Ambient, OutdoorAmbient = LightingSettings[LightingPeriod].OutdoorAmbient, ShadowSoftness = LightingSettings[LightingPeriod].ShadowSoftness})
Tween:Play()
Tween.Completed:Connect(function()
wait(1)
CurrentLightingPeriod = module.GetLightingPeriod()
end)
module.HandleLightsLightingPeriod(LightingPeriod, "Tween")
end
function module.TweenWeather(WeatherType) --Tweens the lighting settings to the designated Weather
if WeatherType ~= "None" then
Weather = true
local SpecifiedWeatherSettings = WeatherSettings[WeatherType]
local Tween1 = TweenService:Create(Lighting, WeatherTweenInformation, {FogEnd = SpecifiedWeatherSettings.FogEnd, FogColor = SpecifiedWeatherSettings.FogColor, Ambient = SpecifiedWeatherSettings.Ambient, OutdoorAmbient = SpecifiedWeatherSettings.OutdoorAmbient, Brightness = SpecifiedWeatherSettings.Brightness, ShadowSoftness = SpecifiedWeatherSettings.ShadowSoftness})
local Tween2 = TweenService:Create(Lighting:FindFirstChildWhichIsA("SunRaysEffect"), WeatherTweenInformation, {Intensity = SpecifiedWeatherSettings.SunRaysIntensity})
local Tween3 = TweenService:Create(Lighting:FindFirstChildWhichIsA("BlurEffect"), WeatherTweenInformation, {Size = SpecifiedWeatherSettings.BlurSize})
local Tween4 = TweenService:Create(Workspace.Terrain, WeatherTweenInformation, {WaterReflectance = SpecifiedWeatherSettings.WaterReflectance, WaterWaveSize = SpecifiedWeatherSettings.WaterWaveSize, WaterWaveSpeed = SpecifiedWeatherSettings.WaterWaveSpeed})
Tween1:Play()
Tween2:Play()
Tween3:Play()
Tween4:Play()
else
Weather = false
local SpecifiedWeatherSettings = WeatherSettings[WeatherType]
local Tween1 = TweenService:Create(Lighting, WeatherTweenInformation, {FogEnd = SpecifiedWeatherSettings.FogEnd, FogColor = SpecifiedWeatherSettings.FogColor, Brightness = SpecifiedWeatherSettings.Brightness})
local Tween2 = TweenService:Create(Lighting:FindFirstChildWhichIsA("SunRaysEffect"), WeatherTweenInformation, {Intensity = SpecifiedWeatherSettings.SunRaysIntensity})
local Tween3 = TweenService:Create(Lighting:FindFirstChildWhichIsA("BlurEffect"), WeatherTweenInformation, {Size = SpecifiedWeatherSettings.BlurSize})
local Tween4 = TweenService:Create(Workspace.Terrain, WeatherTweenInformation, {WaterReflectance = SpecifiedWeatherSettings.WaterReflectance, WaterWaveSize = SpecifiedWeatherSettings.WaterWaveSize, WaterWaveSpeed = SpecifiedWeatherSettings.WaterWaveSpeed})
Tween1:Play()
Tween2:Play()
Tween3:Play()
Tween4:Play()
module.TweenLightingSettings(module.CheckForPeriodChange()) --// Tweens the Ambient, OutdoorAmbient, and ShadowSoftness to wahtever the current Lighting Period is
local LightingPeriod = module.GetLightingPeriod()
module.HandleLightsLightingPeriod(LightingPeriod, "Tween")
end
module.HandleLightsWeather(WeatherType, "Tween") --// Tweens lights
end
--// Advanced Functions
function module.SetLights(ActivateLights) --// Immediately sets the lights to an on/off status
for i, v in pairs (ChangingLights) do
--//Parts index
if i == "Parts" then
for x, c in pairs (v) do
--Error in that only one table c is appearing, not parsing through them all
--// Creates InstanceTable
if c.InstanceTable == nil then
c.InstanceTable = module.GatherInstanceTable(c.InstanceName)
end
--// Sets lights to on
if ActivateLights == true then
for n, m in pairs (c.InstanceTable) do
if module.LightRandomIllumination(c.ChanceOfIllumination) == true then
m.Color = c.LitColor
m.Material = c.LitMaterial
end
end
--// Sets lights off
elseif ActivateLights == false then
for n, m in pairs (c.InstanceTable) do
m.Color = c.UnlitColor
m.Material = c.UnlitMaterial
end
else
warn("[ABC] Hmm, this warning should never be hit - contact https_KingPie!!")
end
end
--// Lights index
elseif i == "Lights" then
for x, c in pairs (v) do
--//Creates InstanceTable
if c.InstanceTable == nil then
c.InstanceTable = module.GatherInstanceTable(c.InstanceName)
end
--// Turns lights on
if ActivateLights == true then
for n, m in pairs (c.InstanceTable) do
if module.LightRandomIllumination(c.ChanceOfIllumination) == true then
m.Brightness = c.LitBrightness
end
end
--// Turns lights off
elseif ActivateLights == false then
for n, m in pairs (c.InstanceTable) do
m.Brightness = c.UnlitBrightness
end
else
warn("[DEF] Hmm, this warning should never be hit - contact https_KingPie!!")
end
end
--// MultiInstances index
elseif i == "MultiInstanceLights" then
for x, c in pairs (v) do
--// Creates InstanceTable
if c.InstanceTable == nil then
c.InstanceTable = module.GatherInstanceTable(c.ReferencePartName)
end
--// Turns lights on
if ActivateLights == true then
for n, TabulatedInstance in pairs (c.InstanceTable) do
if module.LightRandomIllumination(c.ChanceOfIllumination) == true then
--// Handles the ReferencePart
if c.ReferencePartType ~= nil then
--// Handles ReferencePartType Light
if c.ReferencePartType == "Light" then
if TabulatedInstance:IsA("PointLight") or TabulatedInstance:IsA("SpotLight") or TabulatedInstance:IsA("SurfaceLight") then
TabulatedInstance.Brightness = c.LitBrightness
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles ReferencePartType Part
elseif c.ReferencePartType == "Part" then
if TabulatedInstance:IsA("BasePart") then
TabulatedInstance.Color = c.LitColor
TabulatedInstance.Material = c.LitMaterial
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
--// Handles the RelatedParts
for a, b in pairs (c.RelatedParts) do
--// Handles Parent relations
if b.RelationType == "Parent" then
if b.RelatedName == TabulatedInstance.Parent.Name or b.RelatedName == nil then
local TargetInstance = TabulatedInstance.Parent
--// Handles Light Instances
if b.InstanceType == "Light" then
if TargetInstance:IsA("PointLight") or TargetInstance:IsA("SpotLight") or TargetInstance:IsA("SurfaceLight") then
TargetInstance.Brightness = b.LitBrightness
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles Part Instances
elseif b.InstanceType == "Part" then
if TargetInstance:IsA("BasePart") then
TargetInstance.Color = b.LitColor
TargetInstance.Material = b.LitMaterial
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
--// Handles Child relations
elseif b.RelationType == "Child" then
if TabulatedInstance:FindFirstChild(b.RelatedName) then
local TargetInstance = TabulatedInstance:FindFirstChild(b.RelatedName)
--// Handles Light Instances
if b.InstanceType == "Light" then
if TargetInstance:IsA("PointLight") or TargetInstance:IsA("SpotLight") or TargetInstance:IsA("SurfaceLight") then
TargetInstance.Brightness = b.LitBrightness
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles Part Instances
elseif b.InstanceType == "Part" then
if TargetInstance:IsA("BasePart") then
TargetInstance.Color = b.LitColor
TargetInstance.Material = b.LitMaterial
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
end
end
end
end
--// Turns Lights Off
elseif ActivateLights == false then
for n, TabulatedInstance in pairs (c.InstanceTable) do
--// Handles the Reference Part
if c.ReferencePartType ~= nil then
--// Handles ReferencePartType Light
if c.ReferencePartType == "Light" then
if TabulatedInstance:IsA("PointLight") or TabulatedInstance:IsA("SpotLight") or TabulatedInstance:IsA("SurfaceLight") then
TabulatedInstance.Brightness = c.UnlitBrightness
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles ReferencePartType Part
elseif c.ReferencePartType == "Part" then
if TabulatedInstance:IsA("BasePart") then
TabulatedInstance.Color = c.UnlitColor
TabulatedInstance.Material = c.UnlitMaterial
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
--// Handles RelatedParts
for a, b in pairs (c.RelatedParts) do
--// Handles Parent Relations
if b.RelationType == "Parent" then
if b.RelatedName == TabulatedInstance.Parent.Name or b.RelatedName == nil then
local TargetInstance = TabulatedInstance.Parent
--// Handles Light Instances
if b.InstanceType == "Light" then
if TargetInstance:IsA("PointLight") or TargetInstance:IsA("SpotLight") or TargetInstance:IsA("SurfaceLight") then
TargetInstance.Brightness = b.UnlitBrightness
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles Part Instances
elseif b.InstanceType == "Part" then
if TargetInstance:IsA("BasePart") then
TargetInstance.Color = b.UnlitColor
TargetInstance.Material = b.UnlitMaterial
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
--// Handles Child Relations
elseif b.RelationType == "Child" then
if TabulatedInstance:FindFirstChild(b.RelatedName) then
local TargetInstance = TabulatedInstance:FindFirstChild(b.RelatedName)
--// Handles Light Instances
if b.InstanceType == "Light" then
if TargetInstance:IsA("PointLight") or TargetInstance:IsA("SpotLight") or TargetInstance:IsA("SurfaceLight") then
TargetInstance.Brightness = b.UnlitBrightness
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles Part Instances
elseif b.InstanceType == "Part" then
if TargetInstance:IsA("BasePart") then
TargetInstance.Color = b.UnitColor
TargetInstance.Material = b.UnitMaterial
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
end
end
end
else
warn("[GHI] Hmm, this warning should never be hit - contact https_KingPie!!")
end
end
else
warn("Index: ".. i .. " not recognized")
end
end
end
function module.TweenLights(ActivateLights) --Tweens lights to an on/off status
for i, v in pairs (ChangingLights) do
--// Parts Index
if i == "Parts" then
for x, c in pairs (v) do
--// Creates InstanceTable
if c.InstanceTable == nil then
c.InstanceTable = module.GatherInstanceTable(c.InstanceName)
end
--// Turns Lights On
if ActivateLights == true then
for n, m in pairs (c.InstanceTable) do
if module.LightRandomIllumination(c.ChanceOfIllumination) == true then
local Tween = TweenService:Create(m, LightingTweenInformation, {Color = c.LitColor})
Tween:Play()
Tween.Completed:Connect(function()
m.Material = c.LitMaterial
end)
end
end
--// Turns Lights Off
elseif ActivateLights == false then
for n, m in pairs (c.InstanceTable) do
local Tween = TweenService:Create(m, LightingTweenInformation, {Color = c.UnlitColor})
Tween:Play()
Tween.Completed:Connect(function()
m.Material = c.LitMaterial
end)
end
else
warn("[ABC] Hmm, this warning should never be hit - contact https_KingPie!!")
end
end
--// Lights index
elseif i == "Lights" then
for x, c in pairs (v) do
--// Creates InstanceTable
if c.InstanceTable == nil then
c.InstanceTable = module.GatherInstanceTable(c.InstanceName)
end
--// Turns Lights on
if ActivateLights == true then
for n, m in pairs (c.InstanceTable) do
if module.LightRandomIllumination(c.ChanceOfIllumination) == true then
local Tween = TweenService:Create(m, LightingTweenInformation, {Brightness = c.LitBrightness})
Tween:Play()
end
end
--// Turns Lights off
elseif ActivateLights == false then
for n, m in pairs (c.InstanceTable) do
local Tween = TweenService:Create(m, LightingTweenInformation, {Brightness = c.UnlitBrightness})
Tween:Play()
end
else
warn("[DEF] Hmm, this warning should never be hit - contact https_KingPie!!")
end
end
--// MultiInstances index
elseif i == "MultiInstanceLights" then
for x, c in pairs (v) do
--// Creates InstanceTable
if c.InstanceTable == nil then
c.InstanceTable = module.GatherInstanceTable(c.ReferencePartName)
end
--// Turns lights on
if ActivateLights == true then
for n, TabulatedInstance in pairs (c.InstanceTable) do --// Access table of instances (value being TabulatedInstance)
if module.LightRandomIllumination(c.ChanceOfIllumination) == true then
--// Handles the reference part
if c.ReferencePartType ~= nil then
--// Handles ReferencePartType Light
if c.ReferencePartType == "Light" then
if TabulatedInstance:IsA("PointLight") or TabulatedInstance:IsA("SpotLight") or TabulatedInstance:IsA("SurfaceLight") then
local Tween = TweenService:Create(TabulatedInstance, LightingTweenInformation, {Brightness = c.LitBrightness})
Tween:Play()
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles ReferencePartType Part
elseif c.ReferencePartType == "Part" then
if TabulatedInstance:IsA("BasePart") then
local Tween = TweenService:Create(TabulatedInstance, LightingTweenInformation, {Color = c.LitColor})
Tween:Play()
Tween.Completed:Connect(function()
TabulatedInstance.Material = c.LitMaterial
end)
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
--// Handles Related Parts
for a, b in pairs (c.RelatedParts) do
--// Handles Parent Relations
if b.RelationType == "Parent" then
if b.RelatedName == TabulatedInstance.Parent.Name or b.RelatedName == nil then
local TargetInstance = TabulatedInstance.Parent
--// Handles InstanceType Light
if b.InstanceType == "Light" then
if TargetInstance:IsA("PointLight") or TargetInstance:IsA("SpotLight") or TargetInstance:IsA("SurfaceLight") then
local Tween = TweenService:Create(TargetInstance, LightingTweenInformation, {Brightness = b.LitBrightness})
Tween:Play()
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles InstanceType Part
elseif b.InstanceType == "Part" then
if TargetInstance:IsA("BasePart") then
local Tween = TweenService:Create(TargetInstance, LightingTweenInformation, {Color = b.LitColor}) --TweenService:Create property named 'Material' cannot be tweened due to type mismatch (property is a 'int', but given type is 'token')
Tween:Play()
Tween.Completed:Connect(function()
TargetInstance.Material = b.LitMaterial
end)
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
--// Handles Child Relations
elseif b.RelationType == "Child" then
if TabulatedInstance:FindFirstChild(b.RelatedName) then
local TargetInstance = TabulatedInstance:FindFirstChild(b.RelatedName)
--// Handles InstanceType Light
if b.InstanceType == "Light" then
if TargetInstance:IsA("PointLight") or TargetInstance:IsA("SpotLight") or TargetInstance:IsA("SurfaceLight") then
local Tween = TweenService:Create(TargetInstance, LightingTweenInformation, {Brightness = b.LitBrightness})
Tween:Play()
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles InstanceType Part
elseif b.InstanceType == "Part" then
if TargetInstance:IsA("BasePart") then
local Tween = TweenService:Create(TargetInstance, LightingTweenInformation, {Color = b.LitColor})
Tween:Play()
Tween.Completed:Connect(function()
TargetInstance.Material = b.LitMaterial
end)
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
end
end
end
end
--// Turns Lights Off
elseif ActivateLights == false then
for n, TabulatedInstance in pairs (c.InstanceTable) do
--// Handles the reference part
if c.ReferencePartType ~= nil then
--// Handles ReferencePartType Light
if c.ReferencePartType == "Light" then
if TabulatedInstance:IsA("PointLight") or TabulatedInstance:IsA("SpotLight") or TabulatedInstance:IsA("SurfaceLight") then
local Tween = TweenService:Create(TabulatedInstance, LightingTweenInformation, {Brightness = c.UnlitBrightness})
Tween:Play()
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles ReferencePartType Part
elseif c.ReferencePartType == "Part" then
if TabulatedInstance:IsA("BasePart") then
TabulatedInstance.Material = c.UnlitMaterial
local Tween = TweenService:Create(TabulatedInstance, LightingTweenInformation, {Color = c.UnlitColor})
Tween:Play()
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
--// Handles RelatedParts
for a, b in pairs (c.RelatedParts) do
--// Handles Parent Relations
if b.RelationType == "Parent" then
if b.RelatedName == TabulatedInstance.Parent.Name or b.RelatedName == nil then
local TargetInstance = TabulatedInstance.Parent
--// Handles InstanceType Light
if b.InstanceType == "Light" then
if TargetInstance:IsA("PointLight") or TargetInstance:IsA("SpotLight") or TargetInstance:IsA("SurfaceLight") then
local Tween = TweenService:Create(TargetInstance, LightingTweenInformation, {Brightness = b.UnlitBrightness})
Tween:Play()
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles InstanceType Part
elseif b.InstanceType == "Part" then
if TargetInstance:IsA("BasePart") then
TargetInstance.Material = b.UnlitMaterial
local Tween = TweenService:Create(TargetInstance, LightingTweenInformation, {Color = b.UnlitColor})
Tween:Play()
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
--// Handles Child Relations
elseif b.RelationType == "Child" then
if TabulatedInstance:FindFirstChild(b.RelatedName) then
local TargetInstance = TabulatedInstance:FindFirstChild(b.RelatedName)
--// Handles InstanceType Light
if b.InstanceType == "Light" then
if TargetInstance:IsA("PointLight") or TargetInstance:IsA("SpotLight") or TargetInstance:IsA("SurfaceLight") then
local Tween = TweenService:Create(TargetInstance, LightingTweenInformation, {Brightness = b.UnlitBrightness})
Tween:Play()
else
warn("Attempt to perform property changes for a light on a non-light")
end
--// Handles InstanceType Part
elseif b.InstanceType == "Part" then
if TargetInstance:IsA("BasePart") then
TargetInstance.Material = b.UnlitMaterial
local Tween = TweenService:Create(TargetInstance, LightingTweenInformation, {Color = b.UnlitColor})
Tween:Play()
else
warn("Attempt to perform property changes for a part on a non-part")
end
end
end
end
end
end
else
warn("[GHI] Hmm, this warning should never be hit - contact https_KingPie!!")
end
end
else
warn("Index: ".. i .. " not recognized")
end
end
end
--// Mechanical Functions
function module.GatherInstanceTable(InstanceName)
local Table = {}
if InstanceName == "" or InstanceName == nil then --// Prevents unnecesssary searching
return {}
end
for i, v in pairs (Workspace:GetDescendants()) do
if v.Name == InstanceName then
table.insert(Table, v)
end