so i have a deep thought about this question earlier i wanted to run script so fast without needing to add wait() and not get time exhaustion error. I wonder if this will do it
for i = 1,math.huge,1 do
-- script you want to execute
end
one is a for loop. it iterates forever because you put in infinite iterations
one is a while loop. it iterates forever because the statement is always true
the first code example is stupid and you shouldnt do it
it depends on the complexity of your code. if you’re doing a simple operation then it will probably not matter much. If you’re doing a complex operation like instancing parts your game will probably hang until the code finishes or the code is forced to stop
If you are looking to run something at a fast rate you should be using RunService’s built in events. wait() can only go to values as low as 0.03 seconds.
Don’t expect changing a while loop to a for loop to suddenly avoid a script exhaustion error. Using a while loop or for loop that has no time to yield will quickly use up available memory.
While loops generally are for when you want to loop constantly.
Repeat loops are the same as while loops but stop when it’s given a true value.
For loops are for iteration, through both tables and numbers.
For loops (other than table iteration) is for incrementing a value:
for i = 0, 1, 0.1 do
-- 0.0, 0,1, 0.2, etc
end
You have fine grain control over the increment steps and such.
As @infiniteRaymond stated for latency connecting to Heartbeat is always better performance wise.
using a for loop with an incredibly long number and a while loop pretty much go at the same speed only difference is the for loop has a theoretical end where as the while loop doesnt but as previously mentioned use the RunService and its functions like heartbeat and RenderStep to run things pretty much on a frame basis (heartbeat is like every other frame)
probably because your only really “allowed” to use it for certain things like camera, im assuming due to the fact itd be bad for game performace to be run large scripts on a framely basis ( or something like that lol)