Am i the first person to find this loop method?

If this is the wrong category then tell me so i can change it

So while i was scripting i wanted my script to load stuff faster and i found

 while task.wait() do 
end

loop slow it only repeat 60 times a second so i thought about

local hi = 0
while true do 
hi +=1
if hi >=500 then 
task.wait()
hi = 0
end
end

Its faster and it waits every 500 repeats instead of every time it repeats
You can chance the 500 to something else
if you want to slow it or make it faster

1 Like

Well instead of task.wait you could use game:GetService("RunService").RenderStepped() or just use while wait do end but I guess this method is alright

Well first and foremost, you are not the first person to discover that type of loop. I personally use a method like that inside of my runservice events to do something every n amount of frames. For your situation, you could also just increase the wait time per loop and get similar results.

I thought i was the first person to find it because i have never seen anyone using it

I meant that way to make it faster i remember the heartbeat being as fast as

while task.wait() do

So i think that loop should be faster than heartbeat
I will test it later and see which one is faster

RenderStepped loops every frame of the client (and can not be used in the server) and so would loop as much as the frames per second of the client. If you have an fps-unlocked, say 144fps, then the loop goess 144 times per second.

So I think if you are on the client, RenderStepped is the fastest (well for the use-case).

Can someone suggest me the use case when would I need a loop this fast?

ehhhh its far faster than what you think its(i edited it to wait after 100 repeats instead of 500)


testing loops.rbxm (7.0 KB)

I think this will be the fastest cycle. By changing 120 to higher numbers, you can achieve higher speeds and more lag.

for i = 0, math.huge do
	print(i)
	if i % 120 == 0 then
		task.wait()
	end
end

Haha, I just noticed that you did the same thing.

1 Like

yeah lol (i dont know how % works tho)

Wow, this is incredible. I just used it for the player camera to follow a moving vehicle and it’s a lot smoother! Thanks!

1 Like

you can use .renderstepped or .heartbeat they are fired for every frame

Okay, that’s what I thought. Still need to learn how to use those ones effectively.

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