I am trying to make a street light that turn on at night and turn off when it is day. can some help me to fix this script.
light = Script.Parent.PointLight function if game.Lighting.TimeOfDay=17 then light.range=0 end end function if game.Lighting.TimeOfDay=7 then light.range=30 end end
A much simple way to do a type of light that is on during the night and off during the day.
while(wait())do local l = game.Lighting:GetMinutesAfterMidnight()/60 script.Parent.PointLight.Enabled = l<6 or l>18 end
light = Script.Parent.PointLight while wait(0) do if game.Lighting.TimeOfDay == "17:00:00" then light.Range=0 elseif game.Lighting.TimeOfDay == "07:00:00" then light.Range=30 end end
The while wait() do
loop constantly runs. That will only do something when it finds the TimeOfDay
to be 1700 hours or 0700 hours. When it does, it'll change the range
property of the light to either 0 or 30.
Hope this helps, don't forget to accept an answer and upvotes are appreciated. Thanks!
This'll help when working with TimeOfDay.
This'll help with anything to do with lighting.
This'll help with the while loop.
Well your scripting is a bit weird, it should look like this
light = Script.Parent.PointLight if game.Lighting.TimeOfDay == 17 then light.range = 0 elseif game.Lighting.TimeOfDay == 7 then light.range = 30 end
You need to learn spacing and indentations.
Use the "tab" key to indent and make sure to put spaces where your ='s are.
Try this and then comment.
light = Script.Parent.PointLight function if game.Lighting.TimeOfDay == 17:00:00 then light.Range=0 end end function if game.Lighting.TimeOfDay == 07:00:00 then light.Range=30 end end
Locked by Thewsomeguy and AmericanStripes
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?