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

What is smaller than wait()?

Asked by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

I've been wondering if there's anything smaller than "wait()". If there is, could you please provide an example of it being in a simple script?

3 answers

Log in to vote
4
Answered by
Relatch 550 Moderation Voter
9 years ago

Something smaller would be game:GetService("RunService").RenderStepped:wait() I have no wiki to refer to, but it shows it as the Tip of The Day quite often.

while true do
    script.Parent.Transparency = 0.5
    game:GetService("RunService").RenderStepped:wait()
    script.Parent.Transparency = 0
end

game:GetService("RunService").RenderStepped:wait() is basically just a wait, but half wait(). To use it, just make it act as a regular wait.

2
Specifically, it's approximately 1/60th of a second; wait is (by default) capped at (at least) 1/30th of a second BlueTaslem 18071 — 9y
0
Wow, didn't know that. Faving this for reference. Redbullusa 1580 — 9y
0
RenderStepped is client sided only, you cannot use RenderStepped in a server script. modFrost 130 — 9y
Ad
Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

According to this Wiki page, if 't' in wait(t) is not specified, the amount of wait time is usually 1/30th of a second (0.0333....).

It could be possible to shorten the wait time (i.e. wait(.01)), but I'm not entirely sure. To test this:

print(wait())

print(wait(.01))

But that's not always a good idea. The problem with short wait times is that the wait() function affects the amount of activity that the given script is taking up (lag). So it is a good idea to lengthen wait() times, depending on how the wait() function is used, because some statements are much "heavier" in activity than others.

Refer to this blog to see an example of how the wait() function is used, and more information on how to alleviate lag.

Log in to vote
0
Answered by 8 years ago

I believe wait() is the fastest you can wait on a server script, however, if you have a localscript you can make this over 2 times faster. It waits for the game to render, so if there is lag, the script will lag too. The delay that wait() causes is about 0.03 seconds (If you wanted the full number I wouldn't have any room because the 3 goes on for infinity). But I see that you need it to be faster. Here is what I would do. You may have heard of the :wait() you can attach to the end of events. What this does is yield the script until that event has fired. If you look around in the game. You may notice a service named RunService. This service runs all sorts of things in the game. It also has an event that fires every time the game renders every object. It has to do this faster than 0.03 seconds. See where I'm going with this? You can use the :wait() command to make the code delay as fast as possible, but not so fast that the human eye cannot catch it. Here is what you do:

game["Run Service"] --This is the RunService Service. However, you can't call it like this. You must use the :GetService() Method

game:GetService("RunService") --We can now successfully call the RunService without any errors. There are many things in the RunService, but for now, we are looking for the RenderStepped Event.

--The game renders very quickly, so this should be quite helpful, right?
--RenderStepped is fired every time the game renders every object, so that way the delay is fast, but not too fast

game:GetService("RunService").RenderStepped

--Now for the :wait() command. :wait() waits for the Event to be fired before doing anything, in other words, yields the script until RenderStepped has been fired. This is very useful in loops.

game:GetService("RunService").RenderStepped:wait()

--There you have it!
--Want to see how you would use this in a script?

local RS = game:GetService("RunService").RenderStepped
for i = 1, 100 do
    print("TOO FAST!!!!")
    RS:wait()
end

--I used the RS variable to easily call the service's event. You don't have to do this, but I recommend it. It should take about 1 second to print "TOO FAST!!!!" 100 times. If you used the usual wait() then it would take a longer time.

I hope this helped!

Answer this question