My game has fog. Light grey fog at night looks ugly, and black fog during the day (with a plain grey skybox) looks ugly, so I tried to make a script that changes the fog color at certain times of day...
It didn't work...
CODE:
if game.Lighting.TimeOfDay == 20 then game.Lighting.FogColor = 0,0,0 if game.Lighting.TimeOfDay == 7 then game.Lighting.FogColor = 191,191,191 end end
How can I fix this???
Thanks in advance
You have some problems with this script. I'll list them off best I can and try to help.
1) You're trying to use your if
statements on lines 1 and 5 as listeners. If statements are NOT listeners. An if statement is a conditional statement that 'stops' the code, so to speak, before continuing. But this only occurs when the script reads the statement. The script reads the code from top to bottom, so unless your lighting's TimeOfDay property was 7 or 20 when the server started then you would get no results. Listeners are events. They 'listen' for something to happen. This is what you need to take advantage of.
2) The FogColor
Property of Lighting takes in a Color3
userdata value. What you supplied wasn't a color3 userdata.
You need to use the Changed
event, which is a member of Lighting. It listens for something in lighting to change.
Secondly, you need to compare the TimeOfDay
Property with a string, not a number.
Thirdly, I would suggest using an elseif
statement in place of your second if
statement. This is correct syntax.
You also need to use the Color3.new
function, to convert your numbers into Color3. But also, the color3 scale takes in numbers out of 255, so you have to divide the numbers by 255 inside the function.
game.Lighting.Changed:connect(function() if game.Lighting.TimeOfDay == "07:00:00" then game.Lighting.FogColor = Color3.new(0,0,0) elseif game.Lighting.TimeOfDay =="20:00:00" then game.Lighting.FogColor = Color3.new(191/255,191/255,191/255) end end)