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

how to check if its night, the light turns on, if its day, the light turns off?

Asked by 3 years ago

hello, so, again, im trying to make a game that where if its day a street light turns off but when its night it turns on, it works when i only change the time in explorer then hit play. can i get help?

if game.Lighting.TimeOfDay = 0 then
game.Workspace.lightfolder.streetlamp1.PointLight.Enabled = true
else
game.Workspace.lightfolder.streetlamp1.PointLight.Enabled = false
end

2 answers

Log in to vote
2
Answered by 3 years ago

Hello, Pencil_Supply. I see that you are struggling to make a working streetlight script. Don't worry, I have you covered. Use this script here:

game.Lighting.Changed:Connect(function(changedProperty)
if changedProperty == "ClockTime" then
    if game.Lighting.TimeOfDay == 0 then
         game.Workspace.lightfolder:WaitForChild("streetlamp1").PointLight.Enabled = true
else
game.Workspace.lightfolder:WaitForChild("streetlamp1").PointLight.Enabled = false
end
end
end)
1
thanks Pencil_Supply 67 — 3y
2
No probs man! Dianetter7B 176 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

You need to make the = sign into a double equal sign. This is because you are saying if game.Lighting.TimeOfDay = 0 which is saying if the of day is set to zero because one = sign is setting something to a value.

You would need to change the script to this -

if game.Lighting.TimeOfDay == 0 then -- Double equals sign
game.Workspace.lightfolder.streetlamp1.PointLight.Enabled = true
else
game.Workspace.lightfolder.streetlamp1.PointLight.Enabled = false
end
0
This would be a working solution if it checks every time Lighting is changed. (As from Dianetters answer) 2_MMZ 1059 — 3y

Answer this question