Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I need help to fix this script?

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

4 answers

✓ Accepted answer

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

1 comment

0

thank that worked

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

1 comment

0

no that did not work

This discussion is preserved as it was. New answers, comments, and votes are closed.