✓ Accepted answer
Your Problem
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.
What You Need To Do
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)
4 comments
Alrighty! Thank you so much, was playing around 30 minutes (which is a long time for me) with the code with no working result. Anyways thanks for the answer and the information.
Accept my answer if it helped! :)
Hold up one more question-- if I wanted to add more time/fog color, dark purple at 19 for instance, would I just use another elseif statement?
Precisely! You need to specify it changing at "19:00:00" and inside the statement change the color to something like Color3.new(111/255, 0, 83/255).