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

What is faster than "wait()"?

I've seen this as the "Tip of the Day" but I forgot it. I'm sure someone knows; care to help?

2 answers

✓ Accepted answer

It's the RenderStepped event of the RunService. This event fires every render frame, which is approximately 1/60th of a second. You can use it like a normal event (which will basically behave like a really fast loop, since the event is constantly firing.)

game:GetService("RunService").RenderStepped:connect(function()
	print("Spamming your output...")
end)

Or simply use the wait() method, which will wait for the event to be fired until continuing.

while true do
	print("Spamming your output...")
	game:GetService("RunService").RenderStepped:wait()
end

In a repeat loop, it's the same.

repeat
	print("Spamming your output...")
	game:GetService("RunService").RenderStepped:wait()
until
	condition

This can only be used in a LocalScript.

6 comments

0

Can you show a way how to implement it in a "repeat wait() until true" script?

0

Read it now.

0

Thanks!

0

Don't forget to put a Wait() after a While True Do statement to stop the client from crashing!

8

Waiting for the RenderStepped event to fire is sufficient to keep your client from crashing.

0

Does "while game:GetService("RunService").RenderStepped:wait() do" work? I've done "while wait() do", so...

here are some things faster than wait:

while true do
	print("thing")
	coroutine.yield()
end

runservice.RenderStepped:connect(function()
	print("thing")
end)

runservice.Heartbeat:connect(function()
	print("thing")
end)

local counter = 1
while true do
	print("thing")
	if counter == 2 then
		counter = 1
		coroutine.yield()
	else
		counter = counter + 1
	end
end

1 comment

0

coroutine.yield() methods don't work sadly

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