Hello! So, I've been working on a place with a friend, and we're trying to make a ceiling light that turns off at night indicating that the store is closed, but turns on when it's day indicating that the store is open. There's no errors in the output, it just does nothing. Here's my current attempt at the script:
1 | while wait( 1 ) do |
2 | if game.Lighting.ClockTime = = 0 then |
3 | script.Parent.PointLight.Enabled = false |
4 | script.Parent.BrickColor = BrickColor.new( "Really black" ) |
5 | else |
6 | script.Parent.PointLight.Enabled = true |
7 | script.Parent.BrickColor = BrickColor.new( "Institutional white" ) |
8 | end |
9 | end |
Any answer that actually works is fine.
(It's a workspace script inside of the light part)
Assuming you have a script that is progressing the ClockTime of the game, here is what needs to be done. The issue was that your code is running on a loop that might not pick up when time = 0
due to the wait(1)
and how quickly the ClockTime
is actually ticking.
First, you can use Changed
to run a function when any property of Lighting
changes.
01 | game.Lighting.Changed:Connect( function (changedProperty) --Lighting property is changed |
02 | if changedProperty = = "ClockTime" then --If ClockTime is changed, then run |
03 | if game.Lighting.ClockTime = = 0 then --Turn off light when ClockTime == 0 |
04 | script.Parent.PointLight.Enabled = false |
05 | script.Parent.BrickColor = BrickColor.new( "Really black" ) |
06 | else --Turn on light if ClockTime ~= 0 |
07 | script.Parent.PointLight.Enabled = true |
08 | script.Parent.BrickColor = BrickColor.new( "Institutional white" ) |
09 | end |
10 | end |
11 | end ) |