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

Expected "end" (to close "do" at line 10), got "else"? What did I do wrong?

Basically, making a day/night cycle, and I'm trying to make fog fade out smoothly at night. That's besides the point. When I open the script, I have a red line under my else, with the error above. I can't find what I did wrong, please help.

Here is code:

local Lighting = game:GetService("Lighting")
local Interval = 0.25
local Change = 0.01

while wait(Interval) do
	Lighting.ClockTime = Lighting.ClockTime + Change
end

if Lighting:GetMinutesAfterMidnight() == 18 * 60 then
	while wait() do
		Lighting.FogStart = Lighting.FogStart + 100
		if Lighting.FogStart == 10000 then
			return end
		else return nil
	end
elseif Lighting:GetMinutesAfterMidnight() == 6 * 60 then
	Lighting.FogStart = Lighting.FogStart - 100
	if Lighting.FogStart == 5000 then
		return end
	else return nil
end

1 comment

0

Put an end at line 16

1 answer

✓ Accepted answer

Your issue is related the missing of end to close your while loop, which should be due to using return end then following with an else without any ends, the following script should be a working solution, however I did not test anything.

My changes were checking with >= rather than ==. I also used break rather than return end

local Lighting = game:GetService("Lighting")
local Interval = 0.25
local Change = 0.01

while wait(Interval) do
    Lighting.ClockTime = Lighting.ClockTime + Change
end

if Lighting:GetMinutesAfterMidnight() == 18 * 60 then
    while wait() do
        Lighting.FogStart = Lighting.FogStart + 100
        if Lighting.FogStart >= 10000 then -- Used >= if your fog can skip ever becoming 10000, you wont be stuck forever
           break
	end
    end
elseif Lighting:GetMinutesAfterMidnight() == 6 * 60 then
    Lighting.FogStart = Lighting.FogStart - 100
    if Lighting.FogStart == 5000 then
        return end
    else return nil
end

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