Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't this if statement work properly?

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.

3 comments

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.

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.

0

@mattscy and thank you as well!

1 answer

✓ Accepted answer

You should probably try use

if lighting.ClockTime >6 and lighting.ClockTime < 18 then

1 comment

0

Thanks man!

This discussion is preserved as it was. New answers, comments, and votes are closed.