Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Fog Color Changing at Certain Times of Day?

Asked by 8 years ago

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

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

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)
0
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. ItsTheELitist 29 — 8y
0
Accept my answer if it helped! :) Goulstem 8144 — 8y
0
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? ItsTheELitist 29 — 8y
0
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). Goulstem 8144 — 8y
Ad

Answer this question