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

Why doesn't this if statement work properly?

Asked by 5 years ago

For some reason the script totally disregards the else statement as if it weren't there:

lighting = game:GetService("Lighting")
clock = lighting.ClockTime
bloom = Instance.new("BloomEffect")
color = Instance.new("ColorCorrectionEffect")
rays = Instance.new("SunRaysEffect")
while true do
    wait(0.01)
    if clock >6 and clock <18 then
        bloom.Enabled = true
        bloom.Intensity = 0.1
        bloom.Size = 56;
        bloom.Threshold = 0.6
        bloom.Parent = lighting
        color.Enabled = true
        color.Brightness = 0.05
        color.Contrast = 0.2
        color.Saturation = 0.7
        color.TintColor = Color3.fromRGB(255,255,255)
        color.Parent = lighting
        rays.Enabled = true
        rays.Intensity = 0.3
        rays.Spread = 1
        rays.Parent = lighting
        lighting.Ambient = Color3.new(0,0,0)
        lighting.Brightness = 1;
        lighting.ColorShift_Bottom = Color3.new(0,0,0)
        lighting.ColorShift_Top = Color3.new(0,0,0)
        lighting.OutdoorAmbient = Color3.new(127/255,127/255,127/255)
        else
        color.TintColor = Color3.fromRGB(54,54,54)
    end
end

And please, before you say something like, "line 2 clocktime won't change" just know that I created a while true do loop with :SetMinutesAfterMidnight() that loops it from 12 and back with an interval of 1 minute/second.

Things I've tried: Since else seemed to not work, I tried elseif which would seem redundant, but what else am I supposed to do? I've also tried using spawn(f) to just get rid of the else altogether, but that still doesn't work.

0
Incapaz was actually right (*cough* for once *cough*) in pointing out that the ClockTime variable wont change, as you are setting the variable to the value of ClockTime when the game first starts rather than the property itself. Use lighting.ClockTime instead of clock for up-to-date time throughout the script. mattscy 3725 — 5y
0
@mattscy He may have been correct but unlike you he didn't offer any solution. So I was sitting here wondering what he mean't. User#22890 0 — 5y
0
@mattscy and thank you as well! User#22890 0 — 5y

1 answer

Log in to vote
0
Answered by
SCP774 191
5 years ago

You should probably try use

if lighting.ClockTime >6 and lighting.ClockTime < 18 then
0
Thanks man! User#22890 0 — 5y
Ad

Answer this question