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

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

Asked by 5 years ago

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.

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 seith14 206 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

0
Thanks you a lot, now I knew now that I must place wait() on such an "script scenario". ;) DieStockEnte 11 — 5y
Ad

Answer this question