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

What is faster than "wait()"?

Asked by 9 years ago

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

2 answers

Log in to vote
21
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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.

0
Can you show a way how to implement it in a "repeat wait() until true" script? whyOmustOitObeOme 7 — 9y
0
Read it now. Perci1 4988 — 9y
0
Thanks! whyOmustOitObeOme 7 — 9y
0
Don't forget to put a Wait() after a While True Do statement to stop the client from crashing! minikitkat 687 — 9y
View all comments (2 more)
8
Waiting for the RenderStepped event to fire is sufficient to keep your client from crashing. Perci1 4988 — 9y
0
Does "while game:GetService("RunService").RenderStepped:wait() do" work? I've done "while wait() do", so... sweetkid01 176 — 6y
Ad
Log in to vote
2
Answered by 6 years ago

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
0
coroutine.yield() methods don't work sadly Simxzn 2 — 3y

Answer this question