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

In if loop is a error that occure a game script timeout, but why?

Hello guys, I have a problem: I get in the Output: Game script timeout I tried many things to solve the problem, but nothing solve them. This is a normal script not a local or a module script. The script do this: The script check if the time after midnight is 1080. I have two other script for this script.

Modulscript:

local minutesAfterMidnight = 780
return minutesAfterMidnight

The second script makes the minutesAfterMidnight work.(<--this script work without error)

I tried this:

--fog
game.Lighting.FogEnd = 8000
game.Lighting.FogStart = 1
minutesAfterMidnight = require(game.ServerScriptService.weathersystem.ModuleScript1)
-- This connect the modul script whit this script /\ 
while true do
  if minutesAfterMidnight == 1080 then
    for count = 1, 7000 do
	 	print("debug3")
		game.Lighting.FogEnd = game.Lighting.FogEnd - 1
		wait (1)
    end
    for count2 = 1, 7000 do
		print("debug4")
		game.Lighting.FogEnd = game.Lighting.FogEnd + 1
		wait (1)
      end
  end
end

between while true do and the last end is the error. I tried to set the count from 7000 to 7 down but that wasn`t the problem (I thought that was the problem) I tried also this:

--fog
game.Lighting.FogEnd = 8000
game.Lighting.FogStart = 1
while true do
  if minutesAfterMidnight == 1080 then
    for count = 1, 7000 do
	 	print("debug3")
		game.Lighting.FogEnd = game.Lighting.FogEnd - 1
		wait (1)
    end
    for count2 = 1, 7000 do
		print("debug4")
		game.Lighting.FogEnd = game.Lighting.FogEnd + 1
		wait (1)
      end
  end
end

I tested instead of minutesAfterMidnight also clocktime == "18:00:00" and I tested to put at the other script _G.minutesAfterMidnight = 780. I houp you knew a solution. Thanks in previous.

1 comment

0

Timeout means that the loop is being run way too many times, You need to add a wait() after while true do, + your minutesAfterMidnight doesn't equal 1080 so

1 answer

✓ Accepted answer

Try doing this:

--fog
game.Lighting.FogEnd = 8000
game.Lighting.FogStart = 1
while true do
	if minutesAfterMidnight == 1080 then
		for count = 1, 7000 do
			print("debug3")
			game.Lighting.FogEnd = game.Lighting.FogEnd - 1
			wait (1)
		end
		for count2 = 1, 7000 do
			print("debug4")
			game.Lighting.FogEnd = game.Lighting.FogEnd + 1
			wait (1)
		end
	end
	wait(1)
end

You need to add a wait time to the end of the while true do function or else it will error or crash the game. I suggest also having a function to make the minutesAfterMidnight become 1080 at some point to set off the event.

1 comment

0

Thanks you a lot, now I knew now that I must place wait() on such an "script scenario". ;)

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