Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Am I properly trying to make parts read game.Lighting.TimeofDay?

Asked by 9 years ago

As most of you may know, the roblox wiki takes you through a Day/Night cycle tutorial along with a script to turn a light on and off, which works for one part.

I attempted to split both of the parts apart so that the ServerScriptStorage handles the passage of time, while each individual part handles turning itself on and off, except that the lights no longer wish to function.

Simple Day/Night code

1minutesAfterMidnight = 0
2while true do
3    minutesAfterMidnight = minutesAfterMidnight + 10 --value is big for the sake of debugging
4    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
5    wait(.1)
6end

code within each of the Light Emitting Parts

1lightPart = script.Parent
2if game.Lighting.TimeOfDay == "06:00:00" then
3        lightPart.Material = Enum.Material.Plastic
4        lightPart.PointLight.Enabled = false
5    end
6    if game.Lighting.TimeOfDay == "18:00:00" then
7        lightPart.Material = Enum.Material.Neon
8        lightPart.PointLight.Enabled = true
9end

Hierarchy to help understand the Parent/Child relationships in the event that that is what I messed up on.

https://gyazo.com/36021087292c35a8be3aa6580ad11215

Original combined code for Day/Night + Light on/off

01lightPart = game.Workspace.StreetLamp.lightPart -- Directory for the light
02minutesAfterMidnight = 0
03while true do
04    minutesAfterMidnight = minutesAfterMidnight + 10 --For Debugging
05    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
06    wait(.1)
07 
08    if game.Lighting.TimeOfDay == "06:00:00" then
09        lightPart.Material = Enum.Material.Plastic
10        lightPart.PointLight.Enabled = false
11    end
12    if game.Lighting.TimeOfDay == "18:00:00" then
13        lightPart.Material = Enum.Material.Neon
14        lightPart.PointLight.Enabled = true
15    end
16end

Thank you in advance for your help and feedback

~MBacon15

Answer this question