How do i run a loop INSTANTLY? (read desc)

fine, but it wont make sense.

Heres the PROG1 code:

CWD.Event:Connect(function(PR)
	if PR == "Started" then
		while WrldData.Cont == true do
			
			
			--if math.random(1, 5) == 1 then
			--	print(effects.AffectWants())
			--end
			--if math.random(1, 20) == 1 then
			--	print(effects.AffectEcon())
			--end
			--CHanged to every month
			
			
			--Adding to the days
			local DateTable = WrldData.ConvertDateToTable(WrldData.Date)
			local DD = tonumber(DateTable.Day)
			local MM = tonumber(DateTable.Month)
			local YY = tonumber(DateTable.Year)
			local NewTable = {
				Day = DD,
				Month = MM,
				Year = YY
			}
			if DD == 30 then
				NewTable.Day = 1

				if MM == 12 then
					NewTable.Month = 1
					NewTable.Year += 1
				else
					NewTable.Month += 1
					if math.random(1, 2) == 1 then
						print(effects.AffectWants())
					end
					if math.random(1, 10) == 1 then
						print(effects.AffectEcon())
					end
					print("New Month New Me :3")
				end
			else 
				NewTable.Day += 1
			end
			if NewTable.Day == WrldData.SunExplosionTime.Day and NewTable.Month == WrldData.SunExplosionTime.Month and NewTable.Year == WrldData.SunExplosionTime.Year then
				WrldData.Cont = false
				EndEvent:Fire()
			end
			local model = game.Workspace.Earth
			local rotation = CFrame.Angles(0, math.rad(RoationIncrease), 0)
			local modelCFrame = model:GetPivot()
			model:PivotTo(modelCFrame * rotation)
			WrldData.Date = WrldData.ConvertTableToDate(NewTable)
			Boards.DateDisp.Screen.SurfaceGui.Frame.Pop.Text = "Date: "..WrldData.Date
			Boards.DateDisp.Screen.Tick:Play()
			----------------------------------------------------------------------------------------------------------------------END







			WrldData.UpdateTick(Score)
			task.wait(WrldData.GameTick)
			print(WrldData.Cont)
		end
	elseif PR == "SleeperrMode" then
		
		
		
	end
end)

PROG1 handles possibilities of action taken, PROG2 i dont wanan show for 3 reasons:
1 its basically the heart of the game, thats like if the person behind the biggest roblox game revealed all their coee
2 its REALYL long and boring
3 it has nothing to do with what i need to do

If u want any questions, ask me

try this, it combines sleepermode into the Started if statement

@Vortexuel560

if PR == "Started" then
   local FastForwardDays = 10 -- Number of days to fast forward each iteration in SleeperMode

   while WrldData.Cont == true do
       local DateTable = WrldData.ConvertDateToTable(WrldData.Date)
       local DD = tonumber(DateTable.Day)
       local MM = tonumber(DateTable.Month)
       local YY = tonumber(DateTable.Year)

       if SleeperMode then
           DD = DD + FastForwardDays
           while DD > 30 do
               DD = DD - 30
               MM = MM + 1
               if MM > 12 then
                   MM = 1
                   YY = YY + 1
               end
           end
       else
           -- Normal day increment logic
           DD = DD + 1
           if DD > 30 then
               DD = 1
               MM = MM + 1
               if MM > 12 then
                   MM = 1
                   YY = YY + 1
               end
           end
       end

       -- Update the world date
       WrldData.Date = WrldData.ConvertTableToDate({Day = DD, Month = MM, Year = YY})

       -- Optionally, add a short delay or condition to exit SleeperMode
       if SleeperMode then
           -- Example: wait(0.1) -- Adjust based on your environment's capabilities
           if YY > 2025 then -- When it hits this year in SleeperMode, exit SleeperMode
               SleeperMode = false
           end
       end

       -- Break condition for the while loop to prevent infinite loop
       if not SleeperMode and YY > 2025 then -- Example condition to break the loop
           break
       end
   end
end

no sleeper mode is supposed to be its own thing…
Its supposed to be when the code is running extreamly fast

yeah it doesnt matter, just have it detect when sleeper mode is true, were just funneling it through the existing if

ill jsut find my own way of doign this

bro is making the sims⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

Bloxbug:

1 Like

If I’m understanding this correctly, you have a system that makes calculations every game tick. This part works fine, but you want to be able to calculate some arbitrary number of ticks, as if fast forwarding the game?

If this is the case, you can just calculate the number of ticks that need to be calculated, then run your calculation functions that many times. Since you know how many times you’ll be running these calculations, you can use a numeric for loop.

Of course, there are trade offs. If there are too many calculations to run, execution of other processes will halt as the server iterates through your loop.

Alternatively, you could try making your simulation calculations deterministic.

For example, say you earn some currency at a rate of 2/second. If this “sleeper mode” speeds up time by a factor of 100, then you could simply calculate the new currency earn rate by multiplying the normal rate by the “sleeper mode” factor of 100. This would allow you to maintain the simulation tick rate, while effectively increasing the speed of the calculations. Of course, this will get more complex as you attempt to simulate different aspects, and can break down if any simulated functions require the previous tick frame’s output.

Ultimately, your approach depends on your game’s design, and you should consider which aspects are feasible.

3 Likes

yeah luckily i tried that and guess what… game gets kinda laggy… its not SUPER laggy its probably like 20-25 frames (my guess)
During the time that im fast forwarding though you arent really doing anything important so its not that bad

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.