I’m currently trying to tween the Lighting properties in my place from a set of values from the ‘day’ values to the ‘night’ values, but I’m not entirely sure how to do that. I’m very new to scripting and am not sure if what I’m asking is possible but for instance I’m trying to smoothly transition the game.Lighting.Ambient from (0,0,0) to (47,47,60). Should I be using tweens or is there a better way to do that being that Tweens are a service as well as Lighting, I’m not entirely sure how to continue.
I like to set the ambient settings based on the time, which you can determine with Lighting’s ClockTime value.
Example
local l = game:GetService("Lighting")
local t = game:GetService("TweenService")
local goal -- We set up variables for later.
while wait(1) do
goal = {}
if l.ClockTime > 18 or l.ClockTime < 6 then
goal.OutdoorAmbient = Color3.new(0, 0, 0)
else
goal.OutdoorAmbient = Color3.new(47, 47, 60)
end
t:create(l, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), goal):Play()
end
Just as a quick learning tool, this is fine, but can do with some elseif statements. Let me know if things don’t quite work!
There are a number of small problems with this code.
Problem No. 1: Please always format and indent your code. It’s very difficult to work with if we only have if
and end
words to tell us where we’re reading.
Problem No. 2: You’re trying to tween the property Lighting.Ambience
with a Vector3 value. This value is actually a Color3 value, so it couldn’t work.
Problem No. 3: The ambience property doesn’t actually control ambient lighting in the way you would expect. The ambience property controls the colour hue to apply to area occluded from the sky. You’re probably looking for both OutdoorAmbient and Ambient if you want this to look realistic.
Problem No. 4: I think that doing this alone isn’t enough to create a realistic day and night cycle. You should probably instead tween the Lighting.TimeOfDay
property, as this changes the time of day in the Skybox, as well as tweening ambient lighting to make a more realistic day and night effect.
Take a look here on how to use this property as I think it may be what you’re looking to tween:
If you want to have a look at the effects of the property and see if it’s right for you, try changing the values in studio to 12:00:00, 00:00:00 and 06:00:00.
The great advantage of using this method is that the time of day will blend automatically. So, it looks dark at night, bright at day and blended in the middle.
Ah, much appreciated. Could you give me some pointers on how to format posts for code blocks? I’m a New Member, so I’m not so versed on this forum site. I also made the script from memory, so that’s probably why I used the wrong type of value.
TimeOfDay is a little weird, as it’s a string value, not a number value. ClockTime is a float value, and doesn’t need much formatting like TimeOfDay (‘01:00:00’ vs 1).
Lastly, I didn’t intend on making a script for the OP that they couldn’t learn from, neither do I expect such a simple script to create realistic lighting right off the bat. I’ll correct the code once I get to better understand the elusive formatting that I’ve yet to understand.
I think you’re looking for something similar to one of my recent creations(focus the lighting, not the block):
Thanks for the reply. I’ll be happy to give you some pointers.
On your question on formatting code, you simply need to press the button resembling a HTML tag in your toolbar above the post box. This will preformat it to code style. Then, to continue the code, you simply push forward the code at least four characters. To exit the code, simply type without indentation. Don’t worry about not formatting, though. I only learn how recently. It simply makes it easier to read .
Your point on the benefits of Lighting.ClockTime
is a good one. You should probably use it in this circumstance. You can even use the blending effect by setting it to a decimal. This makes it a lot easier.
Finally, I think it’s good that the script posted doesn’t give a full day/night system, as that would be spoonfeeding as I said above. However, I do think that using the built in day/night system would give a better effect than trying to use ambient settings to recreate it.