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

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

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

✓ Accepted answer

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)

2 comments

1

thanks

2

No probs man!

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

1 comment

0

This would be a working solution if it checks every time Lighting is changed. (As from Dianetters answer)

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