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

I need help to fix this script? [closed]

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

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?

4 answers

Log in to vote
1
Answered by
Seenit 80
10 years ago

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
0
thank that worked mrpoliceman2004 20 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
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.

Log in to vote
-2
Answered by 10 years ago

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.

Log in to vote
-3
Answered by 10 years ago
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
0
no that did not work mrpoliceman2004 20 — 10y