For some reason the first equal sign shows up as an error in the script. The script isn't working, either. What am I doing wrong?
1 | if game.Lighting.TimeOfDay = "18:00:00" then |
2 | script.Parent.BrickColor = BrickColor.new( "Really yellow" ) elseif |
3 | game.Lighting.TimeOfDay = "6:00:00" then |
4 | script.Parent.BrickColor = BrickColor.new( "Really black" ) |
5 | end |
Same thing as funyun said but:
1 | game:GetService( "Lighting" ).Changed:connect( function () --Use Changed instead of while loops to make less lag |
2 | if game.Lighting.TimeOfDay = = "18:00:00" then |
3 | script.Parent.BrickColor = BrickColor.new( "New yeller" ) --Really yellow is not a color! |
4 | elseif game.Lighting.TimeOfDay = = "6:00:00" then |
5 | script.Parent.BrickColor = BrickColor.new( "Really black" ) |
6 | end |
7 | end ) |
Hope it helps!
In conditionals, if you want to check if two things are equal, you use ==, not =. When you're setting values, like changing a part's BrickColor, you use =.
You will also need to constantly check the time. When the game runs, the script will only check the time once, and then it will do nothing else. Let's make a loop to solve this.
1 | while wait() do --Every time this loop runs, it will check the time, and if the time is 6 AM or 6 PM, it will do the stuff. |
2 | if game.Lighting.TimeOfDay = = "18:00:00" then |
3 | script.Parent.BrickColor = BrickColor.new( "Really yellow" ) elseif |
4 | game.Lighting.TimeOfDay = = "6:00:00" then |
5 | script.Parent.BrickColor = BrickColor.new( "Really black" ) |
6 | end |
7 | end |